home *** CD-ROM | disk | FTP | other *** search
/ Meeting Pearls 4 / Meeting Pearls Vol. IV (1996)(GTI - Schatztruhe)[!].iso / Pearls / midi / misc / Midi2TeX / src / tp_m2t16.c < prev    next >
C/C++ Source or Header  |  1994-03-30  |  110KB  |  4,555 lines

  1. /* Output from p2c, the Pascal-to-C translator */
  2. /* From input file "tp_m2t13.pas" */
  3.  
  4.  
  5. /*$R+,S+,D+,F+*/
  6. /******************************************************************/
  7. /* This is the C-version of MIDI2TeX. The majority of the source  */
  8. /* is generated by P2C. Further adjustments were performed manually */
  9. /*                                                                */
  10. /*                                 19-9-93                        */
  11. /******************************************************************/
  12.  
  13.  
  14. #ifndef TP_DECL_H
  15. #include "tp_decl.h"
  16. #endif
  17.  
  18. #ifndef TP_MISC_H
  19. #include "tp_misc.h"
  20. #endif
  21. #ifndef TP_DEBUG_H
  22. #include "tp_debug.h"
  23. #endif
  24. #ifndef TP_M2TF4_H
  25. #include "tp_m2tf4.h"
  26. #endif
  27. #ifndef TP_HEAP1_H
  28. #include "tp_heap1.h"
  29. #endif
  30. #ifndef TP_MIDI_H
  31. #include "tp_midi.h"
  32. #endif
  33.  
  34. #include "tp_m2t16.h"
  35.  
  36. #include <stdlib.h>
  37. #include <string.h>
  38. #include <stdio.h>
  39. #include <math.h>
  40.  
  41. #ifdef THINK_C
  42. #include <console.h>
  43. #include <Files.h>
  44. FInfo fileInfo;
  45. #endif
  46.  
  47. /* Set the stack size to be greater than the default. */
  48. /* This declaration must go in the global data area.  */
  49.  
  50. #ifdef __TURBOC__
  51. extern unsigned _stklen = 65536;
  52. #endif
  53.  
  54.  
  55. /*************************************************************/
  56. static Void NewErrorExit()
  57. {
  58. /*************************************************************/
  59. #ifdef __TURBOC__
  60. Char Str1[128];
  61.  
  62.    if (_doserrno >0) {
  63.      if (MidiFileOpened)
  64.     fprintf(TexFile,"%% MIDI2TeX processing ended due to runtime error \n");
  65.      sprintf(STR1, "...wait a minute, this was a runtime error, of type : %d ",_doserrno);
  66.      ToBothEr(STR1);
  67.      }
  68.  
  69. #endif
  70.   if (MidiFileOpened) {
  71.     if (MidiFile != NULL)
  72.       fclose(MidiFile);
  73.     MidiFile = NULL;
  74.     if (TexFile != NULL)
  75.         fclose(TexFile);
  76.     TexFile = NULL;
  77. #ifdef THINK_C
  78. /* here we set the filetype and file creator of the TeX file for an easy switch to MSWord */
  79.     CtoPstr(TeXFileName.p);
  80.     GetFInfo(TeXFileName.p, 0, &fileInfo);
  81.     fileInfo.fdType = *((unsigned long *) "TEXT");
  82.     fileInfo.fdCreator = *((unsigned long *) "MSWD");
  83.     SetFInfo(TeXFileName.p, 0, &fileInfo);
  84. #endif
  85. /*     freemem(TexBuf); /* this seems to be not necessary */
  86.     WriteDebugInfo("Closing Midi & Tex File...");
  87.   }
  88.   if (DebugFileOpened) {
  89.     if (DebugFile != NULL)
  90.       fclose(DebugFile);
  91.     DebugFile = NULL;
  92. /*    freemem(DebBuf); /* this seems to be not necessary */
  93.     if (Debug)
  94.       printf("Closing up Debugging logger...\n");
  95.   }
  96.   /* free(Ms); */
  97.   KillNotePool();
  98.   KillNoteLists();
  99.   for (i = 1; i <= NoTracks; i++)
  100.     KillFilRec(&TrackArray[i - 1].FilRec);
  101. }  /* NewErrorExit */
  102.  
  103.  
  104. #define eps             3
  105. #define eps_            0.1
  106.  
  107. boolean CheckChordNotes(Note1, Note2)
  108. NoteRecord Note1, Note2;
  109. {
  110.   /*************************************************************/
  111.   /*  This function checks if notes 1 and 2 form a chord       */
  112.   /*************************************************************/
  113.   boolean Result;
  114.  
  115.   switch (TimeDiff(Note1.StartTime, Note2.StartTime)) {
  116.  
  117.   case -3:
  118.   case -2:
  119.   case -1:
  120.   case 0:
  121.   case 1:
  122.   case 2:
  123.   case 3:
  124.     if (Note1.NoteType == Note2.NoteType)
  125.       Result = true;
  126.     else
  127.       Result = false;
  128.     break;
  129.  
  130.   default:
  131.     Result = false;
  132.     break;
  133.   }/* case */
  134.   return Result;
  135. }  /* CheckChordNotes */
  136.  
  137. #undef eps
  138.  
  139.  
  140.  
  141. /********************************************************/
  142.  long NoteLength(ThisNote)
  143. NoteRecord ThisNote;
  144. {
  145.   /********************************************************/
  146.   return (TimeDiff(ThisNote.EndTime, ThisNote.StartTime));
  147. }
  148.  
  149.  
  150.  
  151. /**************************************************************/
  152.  Void ResetChordArray(ThisStack)
  153. ChordRecord *ThisStack;
  154. {
  155.   /*************************************************************/
  156.   memset(ThisStack, 0, sizeof(ChordArrayType));
  157. }
  158.  
  159. /**************************************************************/
  160.  Void ResetBeamArray(ThisArray)
  161. BeamRecord *ThisArray;
  162. {
  163.   /*************************************************************/
  164.   memset(ThisArray, 0, sizeof(BeamArrayType));
  165. }
  166.  
  167. /**************************************************************/
  168.  Void ResetAccKeys()
  169. {
  170.   /*************************************************************/
  171.   long i, FORLIM;
  172.   TrackRecord *WITH;
  173.  
  174.   FORLIM = ntracks;
  175.   for (i = 0; i < FORLIM; i++) {
  176.     WITH = &TrackArray[i];
  177.     memset((&WITH->AccKey), 0, sizeof(AccKeyType));
  178.   }
  179. }
  180.  
  181.  
  182. /******************************************************/
  183.  Void SortChord(ThisTrack, ThisChord)
  184. TrackRecord *ThisTrack;
  185. ChordRecord *ThisChord;
  186. {
  187.   /******************************************************/
  188.   long mn, mx, k, mean;
  189.   NoteRecord *N, *P, *Nmx, *Nmn;
  190.   long Border;
  191. /*  Char STR1[256]; */
  192.  
  193.   mn = 32000;
  194.   mx = 0;
  195.   mean = 0;
  196.   k = 0;
  197.   N = ThisChord->StartNote;
  198.   NextNote(ThisChord->EndNote, &P);
  199.   do {
  200.     mean += N->NoteVal;
  201.     k++;
  202.     if (N->NoteVal > mx) {
  203.       mx = N->NoteVal;
  204.       Nmx = N;
  205.     }
  206.     if (N->NoteVal < mn) {
  207.       mn = N->NoteVal;
  208.       Nmn = N;
  209.     }
  210.     NextNote(N, &N);
  211.   } while (N != P);
  212.   mean /= k;
  213.  
  214.   switch (ThisTrack->Clef) {
  215.  
  216.   case VIOLIN:
  217.     Border = 70;
  218.     break;
  219.  
  220.   case BASS:
  221.     Border = 52;
  222.     break;
  223.   }
  224.  
  225.   if (mean > Border) {   /* put lowest last , staff should be down */
  226.     if (ThisChord->EndNote == Nmn) {
  227.       WriteDebugInfo("No sort necessary");
  228.       return;
  229.     }
  230.     sprintf(STR1, "Exchanging note %3d with %3d",ThisChord->EndNote->NoteVal, Nmn->NoteVal);
  231.     WriteDebugInfo(STR1);
  232.     if (ThisChord->StartNote == Nmn)   /* else ???*/
  233.       ThisChord->StartNote = ThisChord->EndNote;
  234.     Exchange(&ThisTrack->NoteList, &Nmn, &ThisChord->EndNote);
  235.     ThisChord->EndNote->ChordNote = true;
  236.     Nmn->ChordNote = false;
  237.     Nmn->Orient = DOWN;
  238.     ThisChord->EndNote = Nmn;
  239.     return;
  240.   }
  241.   /* with thistrack */
  242.   if (ThisChord->EndNote == Nmx) {
  243.     WriteDebugInfo("No sort necessary");
  244.     return;
  245.   }
  246.   sprintf(STR1, "Exchanging note %3d with %3d",ThisChord->EndNote->NoteVal,Nmx->NoteVal);
  247.   WriteDebugInfo(STR1);
  248.   if (ThisChord->StartNote == Nmx)
  249.     ThisChord->StartNote = ThisChord->EndNote;
  250.   Exchange(&ThisTrack->NoteList, &Nmx, &ThisChord->EndNote);
  251.   ThisChord->EndNote->ChordNote = true;
  252.   Nmx->ChordNote = false;
  253.   Nmx->Orient = UP;
  254.   ThisChord->EndNote = Nmx;
  255.  
  256.   /* put highest note last, staff should be up */
  257. }  /* SortChord */
  258.  
  259.  
  260.  
  261. /******************************************************/
  262.  Void ChordFind(ThisTrack)
  263. TrackRecord *ThisTrack;
  264. {
  265.   /******************************************************/
  266.   long dstart;
  267.   uchar VoidNotes;
  268.   NoteRecord *N, *P, *Q_;
  269.   boolean Chording;
  270.   ChordRecord *WITH1;
  271. /*   Char STR1[256]; */
  272.  
  273.   long FORLIM;
  274.  
  275.   WriteDebugInfo("Starting ChordFind");
  276.   Chording = false;
  277.   ThisTrack->ChStackPoint = 1;
  278.   ThisTrack->ChStackEnd = 1;
  279.   VoidNotes = 0;
  280.   FirstNote(ThisTrack->NoteList, &N);
  281.   FirstNote(ThisTrack->NoteList, &P);
  282.   do {
  283.  
  284.     switch (N->Event) {
  285.  
  286.     case REST:   /* this should end any pending chords */
  287.       break;
  288.  
  289.     case VOID:
  290.       VoidNotes++;
  291.       break;
  292.  
  293.     case NOTEON:
  294.     case NOTEOFF:
  295.       if (!Chording) {
  296.     WITH1 = &ThisTrack->ChordArray[ThisTrack->ChStackPoint - 1];
  297.     WITH1->StartNote = N;
  298.     N->ChordNote = true;
  299.     WITH1->NoNotes = 1;
  300.     Chording = true;
  301.       } else {  /* if Chording */
  302.     PrevNote(N, &Q_);
  303.     dstart = TimeDiff(N->StartTime, Q_->StartTime);
  304.     if (N->NoteType == Q_->NoteType && dstart < QuantTime)
  305.     {  /* notetypes and starttimes are equal */
  306.       WITH1 = &ThisTrack->ChordArray[ThisTrack->ChStackPoint - 1];
  307.       sprintf(STR1, "Note %3d in chord", N->NoteVal);
  308.       WriteDebugInfo(STR1);
  309.       N->ChordNote = true;
  310.       WITH1->EndNote = N;
  311.       WITH1->NoNotes++;
  312.     } else {  /* note types or starttimes are not equal */
  313.       if (ThisTrack->ChordArray[ThisTrack->ChStackPoint - 1].NoNotes > 1)
  314.       {  /* there was a chord on the stack */
  315.         WriteDebugInfo("Finishing up a chord..");
  316.  
  317.         ThisTrack->ChordArray[ThisTrack->ChStackPoint - 1].ChordFinished = true;
  318.         WITH1 = &ThisTrack->ChordArray[ThisTrack->ChStackPoint - 1];
  319.  
  320.         /* start a possible beam at this chord's note */
  321.         WITH1->EndNote->ChordNote = false;
  322.         ThisTrack->ChStackPoint++;
  323.         WITH1 = &ThisTrack->ChordArray[ThisTrack->ChStackPoint - 1];
  324.         N->ChordNote = true;
  325.         WITH1->StartNote = N;
  326.         WITH1->NoNotes++;
  327.       } else {  /* there was no chord on the stack */
  328.         WITH1 = &ThisTrack->ChordArray[ThisTrack->ChStackPoint - 1];
  329.         WITH1->StartNote->ChordNote = false;
  330.         N->ChordNote = true;
  331.         WITH1->StartNote = N;
  332.         WITH1->NoNotes = 1;
  333.       }
  334.  
  335.     }
  336.       }
  337.       break;
  338.       /* Event=NOTEON,NOTEOFF */
  339.     }/* End Case */
  340.     NextNote(N, &N);   /* repeat loop */
  341.   } while (N != P);   /* FirstNote(NoteList) */
  342.  
  343.   WriteDebugInfo("Processed all events in the notelist");
  344.  
  345.   switch (ThisTrack->ChordArray[ThisTrack->ChStackPoint - 1].NoNotes) {
  346.       /* WITH */
  347.  
  348.   case 2:
  349.   case 3:
  350.   case 4:
  351.   case 5:
  352.   case 6:
  353.   case 7:
  354.   case 8:
  355.   case 9:
  356.   case 10:  /* finish up chord */
  357.     WITH1 = &ThisTrack->ChordArray[ThisTrack->ChStackPoint - 1];
  358.     WITH1->ChordFinished = true;
  359.     WITH1->EndNote->ChordNote = false;
  360.     ThisTrack->ChStackEnd = ThisTrack->ChStackPoint;
  361.     break;
  362.  
  363.   case 1:  /* Cancel the one-note-chord */
  364.     WITH1 = &ThisTrack->ChordArray[ThisTrack->ChStackPoint - 1];
  365.     WITH1->StartNote->ChordNote = false;
  366.     WITH1->StartNote = NULL;
  367.     ThisTrack->ChStackPoint--;
  368.     ThisTrack->ChStackEnd = ThisTrack->ChStackPoint;
  369.     break;
  370.  
  371.   case 0:  /* there are no notes in the stack */
  372.     ThisTrack->ChStackPoint--;
  373.     ThisTrack->ChStackEnd = ThisTrack->ChStackPoint;
  374.     break;
  375.   }/* CASE */
  376.  
  377.   sprintf(STR1, "Resorting %3d Chord(s) in this measure",ThisTrack->ChStackEnd);
  378.   WriteDebugInfo(STR1);
  379.   sprintf(STR1, "Before sort: %s",
  380.       ChordNoteList2String(STR1, ThisTrack->NoteList));
  381.   /* WriteDebugInfo('Before sort: '+NoteList2String(NoteList)); */
  382.   WriteDebugInfo(STR1);
  383.   FORLIM = ThisTrack->ChStackEnd;
  384.   for (i = 1; i <= FORLIM; i++)
  385.     SortChord(ThisTrack, &ThisTrack->ChordArray[i - 1]);
  386.   sprintf(STR1, "After sort: %s",
  387.       ChordNoteList2String(STR1, ThisTrack->NoteList));
  388.   /* WriteDebugInfo('After sort: '+NoteList2String(NoteList)); */
  389.   WriteDebugInfo(STR1);
  390.   sprintf(STR1, "Number of void notes found in this measure by chordfind:%3d",
  391.       VoidNotes);
  392.   WriteDebugInfo(STR1);
  393.   WriteDebugInfo("ChordFind ready");
  394. }  /* ChordFind */
  395.  
  396. #undef eps_
  397.  
  398. /******************************************************/
  399.  long FindSlurrIndex()
  400. {
  401.   /******************************************************/
  402.   long i;
  403.  
  404.   i = 0;
  405.   while (SlurrIndexes[i]==true && i < MAXSLURR)
  406.     i++;
  407.   if (i >= MAXSLURR)
  408.     ErrorExit(16L);
  409.   SlurrIndexes[i] = true;
  410.   return i;
  411. }
  412.  
  413. /*********************************************************/
  414. long IsSlurred(N, ThisTrack)
  415. NoteRecord *N;
  416. TrackRecord *ThisTrack;
  417. {
  418.   /******************************************************/
  419.   long i, B, FORLIM;
  420.   SlurrRecord *WITH;
  421.  
  422.   B = 0;
  423.   FORLIM = ThisTrack->SlurrPt;
  424.   for (i = 1; i <= FORLIM; i++) {
  425.     WITH = &(ThisTrack->SlurrArray[i - 1]);
  426.     if (WITH->Occupied==true && WITH->NotePnt == N)
  427.       B = i;
  428.   }
  429.   return B;
  430. }
  431.  
  432.  
  433. /********************************************************/
  434.  Void FindSlurrNote(ThisTrack, CurMeasure)
  435. TrackRecord *ThisTrack;
  436. long CurMeasure;
  437. {
  438.   /********************************************************/
  439.   NoteRecord *N, *P;
  440.   long SlurrI1, SlurrI2;
  441.   MeasureTime TmpTime;
  442.   SlurrRecord *WITH2;
  443. /*   Char STR1[256]; */
  444.  
  445.   WriteDebugInfo("Starting SlurrFinder");
  446.   SetTim(&TmpTime, (int)(CurMeasure + 1), 0);
  447.   FirstNote(ThisTrack->NoteList, &N);
  448.   P = N;
  449.   do {   /* with TrackList */
  450.     switch (N->Event) {
  451.  
  452.     case REST:   /* A rest occurred, their ought not to be any slurrs */
  453.       break;
  454.  
  455.     case NOTEON:
  456.     case NOTEOFF:
  457.       if (TimeDiff(TmpTime, N->EndTime) < 0) {
  458.     /* The EndTime of this note is beyond the end of current measure */
  459.     /* So, slurr this note */
  460.     SlurrI2 = IsSlurred(N, ThisTrack);
  461.     if (SlurrI2 == 0) {   /* was not already slurred */
  462.       SlurrI1 = FindSlurrIndex();
  463.       ThisTrack->SlurrPt++;
  464.       WITH2 = &ThisTrack->SlurrArray[ThisTrack->SlurrPt - 1];
  465.       sprintf(STR1, "At note %3d a startslurr", N->NoteVal);
  466.       WriteDebugInfo(STR1);
  467.       WITH2->NotePnt = N;
  468.       WITH2->NoteVal = N->NoteVal;
  469.       WITH2->KindOf = STARTSLUR;
  470.       WITH2->Numb1 = SlurrI1;
  471.       WITH2->Occupied = true;
  472.       ThisTrack->Slurring = true;
  473.       /*Slurring:=FALSE;*/
  474.       /* this disables slurring for test purpose */
  475.     }  /* If SlurrI2=0 */
  476.     else {
  477.       /* Note was already slurred.  */
  478.       SlurrI1 = FindSlurrIndex();
  479.       WITH2 = &ThisTrack->SlurrArray[ThisTrack->SlurrPt - 1];
  480.       sprintf(STR1, "At note %3d a repeatslurr", N->NoteVal);
  481.       WriteDebugInfo(STR1);
  482.       WITH2->KindOf = REPEATSLUR;
  483.       WITH2->Numb2 = WITH2->Numb1;
  484.       WITH2->Numb1 = SlurrI1;
  485.     }
  486.       } else {
  487.     /* The EndTime of this note is in current measure */
  488.     if (ThisTrack->Slurring) {
  489.       SlurrI2 = IsSlurred(N, ThisTrack);
  490.       if (SlurrI2 > 0) {   /* this note was slurred */
  491.         WITH2 = &ThisTrack->SlurrArray[SlurrI2 - 1];
  492.         sprintf(STR1, "At note %3d end slurr", N->NoteVal);
  493.         WriteDebugInfo(STR1);
  494.         WITH2->KindOf = ENDSLUR;
  495.         WITH2->Numb2 = WITH2->Numb1;
  496.       }
  497.     }
  498.       }
  499.       break;
  500.     }/* case */
  501.     NextNote(N, &N);
  502.   } while (N != P);   /* FirstNote(NoteList) */
  503. }  /* FindSlurrNote*/
  504.  
  505.  
  506. /******************************************************************/
  507.  Void ChopRest(N, ThisTrack, ThisMsre)
  508. NoteRecord **N;
  509. TrackRecord *ThisTrack;
  510. long ThisMsre;
  511. {
  512.   /******************************************************************/
  513.   NoteRecord *P;
  514.   long dt;
  515.   MeasureTime TmpTime;
  516.   unsigned short DivTime, divider;
  517.   uchar cnt;
  518. /*  Char STR1[256]; */
  519.  
  520.   WriteDebugInfo("Starting ChopRest ");
  521.  
  522.   SetTim(&TmpTime, (int)(ThisMsre + 1), 0);
  523.   dt = TimeDiff((*N)->EndTime, TmpTime);
  524.   if (dt > 0) {   /* Rest is longer than and of current measure */
  525.     WriteDebugInfo("Chopping rest off at end of this measure");
  526.     P = GetFreeNote();
  527.     Insert(&ThisTrack->NoteList, (*N)->Next, P);
  528.     P->EndTime = (*N)->EndTime;
  529.     P->StartTime = TmpTime;
  530.     (*N)->EndTime = TmpTime;
  531.     P->Event = REST;
  532.   }
  533.   dt = TimeDiff((*N)->EndTime, (*N)->StartTime);
  534.   DivTime = PieceContr.Division * 8;
  535.   cnt = 0;
  536.   while (dt > PieceContr.Division / 8) {
  537.     divider = 0;
  538.     while (divider == 0) {
  539.       DivTime >>= 1;
  540.       divider = dt / DivTime;
  541.       cnt++;
  542.     }
  543.     SetTim(&TmpTime, 0, DivTime);
  544.     AddTime((*N)->StartTime, TmpTime, &TmpTime);
  545.     (*N)->NoteType = (NoteTypes)cnt;
  546.     dt -= divider * DivTime;
  547.     if (dt <= PieceContr.Division / 16)
  548.       continue;
  549.     P = GetFreeNote();
  550.     Insert(&ThisTrack->NoteList, (*N)->Next, P);
  551.     P->Event = REST;
  552.     P->EndTime = (*N)->EndTime;
  553.     (*N)->EndTime = TmpTime;
  554.     P->StartTime = TmpTime;
  555.     sprintf(STR1, "Chopping rest into: [%3ld:%3ld-%3ld:%3ld]and [%3ld:%3ld-%3ld:%3ld]",
  556.         (*N)->StartTime.Measure,(*N)->StartTime.MPart,
  557.         (*N)->EndTime.Measure, (*N)->EndTime.MPart,
  558.         P->StartTime.Measure,  P->StartTime.MPart,
  559.         P->EndTime.Measure, P->EndTime.MPart);
  560.     WriteDebugInfo(STR1);
  561.     *N = P;
  562.   }  /* while */
  563.   WriteDebugInfo("End ChopRest");
  564. }  /* ChopRest */
  565.  
  566.  
  567. /******************************************************/
  568.  Void FindNoteTypes(ThisTrack, ThisMsre)
  569. TrackRecord *ThisTrack;
  570. long ThisMsre;
  571. {
  572.   /******************************************************/
  573.   NoteRecord *N, *P;
  574.   long dt, Divisor, Rst;
  575.   MeasureTime TmpTime;
  576.   NoteRecord *WITH1;
  577. /*  Char STR1[256]; */
  578.  
  579.   FirstNote(ThisTrack->NoteList, &N);
  580.   P = N;
  581.   do {   /* with TrackList */
  582.     WITH1 = N;   /* WIth N^ */
  583.  
  584.     switch (WITH1->Event) {
  585.  
  586.     case NOTEON:
  587.     case NOTEOFF:
  588.       switch (ThisTrack->Clef) {
  589.  
  590.       case VIOLIN:
  591.     if (WITH1->NoteVal > 70)
  592.       WITH1->Orient = DOWN;
  593.     else
  594.       WITH1->Orient = UP;
  595.     break;
  596.  
  597.       case BASS:
  598.     if (WITH1->NoteVal > 52)
  599.       WITH1->Orient = DOWN;
  600.     else
  601.       WITH1->Orient = UP;
  602.     break;
  603.       }
  604.       break;
  605.     }
  606.  
  607.     switch (WITH1->Event) {
  608.  
  609.     case NOTEON:
  610.       WriteDebugInfo("Found a non-closed note");
  611.       sprintf(STR1, "Starting at %3d:%3d",(int)WITH1->StartTime.Measure,
  612.           (int)WITH1->StartTime.MPart);
  613.       WriteDebugInfo(STR1);
  614.       sprintf(STR1, "Ending at %3d:%3d",(int)WITH1->EndTime.Measure,
  615.           (int)WITH1->EndTime.MPart);
  616.       WriteDebugInfo(STR1);
  617.       /* this prevent that the endtimes (1000) of non-closed notes */
  618.       /* faul up the selection of the notetype */
  619.       SetTim(&TmpTime, (int)(ThisMsre + 1), 0);
  620.       break;
  621.  
  622.     /* if the note ends in this measure, check if its length is */
  623.     /* longer than a whole note */
  624.     /* check if a noteoff is shut off in this measure */
  625.     default:
  626.       SetTim(&TmpTime, (int)(ThisMsre + 1), 0);
  627.       dt = TimeDiff(TmpTime, WITH1->EndTime);
  628.       if (dt >= 0)   /* Note is closed in this measure ... */
  629.     TmpTime = WITH1->EndTime;
  630.       break;
  631.     }/* case */
  632.  
  633.  
  634.     if (Quantizing)
  635.       Quantize(&N);
  636.  
  637.     /* DO not use EndTime but the previously defined TmpTime */
  638.     dt = TimeDiff(TmpTime, WITH1->StartTime);
  639.     if (dt < 0)
  640.       WriteDebugInfo("Found an event with neg length !");
  641.     if (dt > 0) {
  642.       if (PieceContr.Division > dt) {
  643.     Divisor = PieceContr.Division / dt;
  644.     Rst = PieceContr.Division % dt * 10 / dt;
  645. /* p2c: tp_m2t13.pas, line 546:
  646.  * Note: Using % for possibly-negative arguments [317] */
  647.     switch (Divisor) {
  648.  
  649.     case 1:
  650.       switch (Rst) {
  651.  
  652.       case 0:
  653.       case 1:
  654.       case 2:
  655.         WITH1->NoteType = Q;
  656.         break;
  657.  
  658.       case 3:
  659.       case 4:
  660.         WITH1->NoteType = CP;
  661.         break;
  662.  
  663.       case 5:
  664.       case 6:
  665.       case 7:
  666.       case 8:
  667.       case 9:
  668.         WITH1->NoteType = C;
  669.         break;
  670.       }
  671.       break;
  672.  
  673.     case 2:
  674.       switch (Rst) {
  675.  
  676.       case 0:
  677.       case 1:
  678.       case 2:
  679.       case 3:
  680.       case 4:
  681.         WITH1->NoteType = C;
  682.         break;
  683.  
  684.       case 5:
  685.       case 6:
  686.       case 7:
  687.       case 8:
  688.         WITH1->NoteType = CCP;
  689.         break;
  690.  
  691.       case 9:
  692.         WITH1->NoteType = C3;
  693.         break;
  694.       }
  695.       break;
  696.  
  697.     case 3:
  698.       switch (Rst) {
  699.  
  700.       case 0:
  701.       case 1:
  702.       case 2:
  703.       case 3:
  704.       case 4:   /* 1/8 trioler */
  705.         WITH1->NoteType = C3;
  706.         break;
  707.  
  708.       case 5:
  709.       case 6:
  710.       case 7:
  711.       case 8:
  712.       case 9:
  713.         WITH1->NoteType = CC;
  714.         break;
  715.       }
  716.       break;
  717.  
  718.     case 4:
  719.       WITH1->NoteType = CC;
  720.       break;
  721.  
  722.     case 5:
  723.     case 6:   /* 1/16 trioler */
  724.       WITH1->NoteType = CC3;
  725.       break;
  726.  
  727.     case 7:
  728.     case 8:
  729.     case 9:
  730.     case 10:
  731.     case 11:
  732.     case 12:
  733.       WITH1->NoteType = CCC;
  734.       break;
  735.  
  736.     default:
  737.       WITH1->NoteType = CCCC;
  738.       break;
  739.     }
  740.       } else {  /* if Division<dt */
  741.     Divisor = dt / PieceContr.Division;
  742.     Rst = dt % PieceContr.Division * 10 / PieceContr.Division;
  743. /* p2c: tp_m2t13.pas, line 573:
  744.  * Note: Using % for possibly-negative arguments [317] */
  745.     switch (Divisor) {
  746.  
  747.     case 1:
  748.       switch (Rst) {
  749.  
  750.       case 0:
  751.       case 1:
  752.         WITH1->NoteType = Q;
  753.         break;
  754.  
  755.       case 2:
  756.       case 3:   /* These notes should be slurred  */
  757.         WITH1->NoteType = QPP;
  758.         break;
  759.  
  760.       case 4:
  761.       case 5:
  762.       case 6:
  763.         WITH1->NoteType = QP;
  764.         break;
  765.  
  766.       case 7:
  767.       case 8:   /* should be longer */
  768.         WITH1->NoteType = QP;
  769.         break;
  770.  
  771.       case 9:
  772.         WITH1->NoteType = H;
  773.         break;
  774.       }
  775.       break;
  776.  
  777.     case 2:
  778.       switch (Rst) {   /* dit klopt nog niet ... */
  779.  
  780.       case 0:
  781.       case 1:
  782.         WITH1->NoteType = H;
  783.         break;
  784.  
  785.       case 2:
  786.       case 3:
  787.         WITH1->NoteType = HPPP;
  788.         break;
  789.  
  790.       case 4:
  791.       case 5:
  792.       case 6:
  793.         WITH1->NoteType = HPP;
  794.         break;
  795.  
  796.       case 7:
  797.       case 8:
  798.         WITH1->NoteType = HP;
  799.         break;
  800.  
  801.       case 9:
  802.         WITH1->NoteType = HP;
  803.         break;
  804.       }
  805.       break;
  806.  
  807.     case 3:
  808.       switch (Rst) {
  809.  
  810.       case 0:
  811.       case 1:
  812.       case 2:
  813.       case 3:
  814.       case 4:
  815.         WITH1->NoteType = HP;
  816.         break;
  817.  
  818.       case 5:
  819.       case 6:
  820.       case 7:
  821.       case 8:
  822.       case 9:
  823.         WITH1->NoteType = WH;
  824.         break;
  825.       }
  826.       break;
  827.  
  828.     case 4:
  829.       switch (Rst) {
  830.  
  831.       case 0:
  832.       case 1:
  833.       case 2:
  834.       case 3:
  835.         WITH1->NoteType = WH;
  836.         break;
  837.  
  838.       case 4:
  839.       case 5:
  840.       case 6:
  841.       case 7:
  842.       case 8:
  843.       case 9:
  844.         WITH1->NoteType = WHPP;
  845.         break;
  846.       }
  847.       break;
  848.  
  849.     case 5:
  850.       WITH1->NoteType = WHPP;
  851.       break;
  852.  
  853.     case 6:
  854.       WITH1->NoteType = WHP;
  855.       break;
  856.     }
  857.       }
  858.     } else {
  859.       /* Do not show note, it has length zero ! */
  860.       if (WITH1->Event == TXT)
  861.     WriteDebugInfo("Hey, here is that metatext again..");
  862.       else {
  863.     WITH1->Event = VOID;
  864.     WriteDebugInfo("Found a void note");
  865.       }
  866.     }
  867.     /* If Event=REST Then ChopRest(N,ThisTrack,ThisMsre); */
  868.     NextNote(N, &N);
  869.   } while (N != P);   /* FirstNote(NoteList) */
  870. }  /* FindNoteTypes */
  871.  
  872. /*********************************************************************/
  873.  long NoteInChord(N, ThisTrack)
  874. NoteRecord *N;
  875. TrackRecord ThisTrack;
  876. {
  877.   /*********************************************************************/
  878.   long Result;
  879.   uchar i;
  880.  
  881.   Result = 0;
  882.   for (i = 1; i <= ThisTrack.ChStackEnd; i++) {
  883.     if (ThisTrack.ChordArray[i - 1].StartNote == N)
  884.       Result = i;
  885.   }
  886.   return Result;
  887. }
  888.  
  889. /*  variables for BeamFind:
  890. struct LOC_BeamFind {
  891.   TrackRecord *ThisTrack;
  892.   uchar BeamPnt;
  893.   NoteRecord *NotePnt;
  894.   boolean Beaming;
  895. } ; */
  896.  
  897. /*--------------------*/
  898.  Void StartBeam(LINK)
  899. struct LOC_BeamFind *LINK;
  900. {
  901.   /*--------------------*/
  902.   BeamRecord *WITH;
  903. /*  Char STR1[256]; */
  904.  
  905.   WITH = &LINK->ThisTrack->BeamArray[LINK->BeamPnt - 1];
  906.   WITH->StartNote = LINK->NotePnt;
  907.   WITH->EndNote = LINK->NotePnt;
  908.   WITH->NoteType = LINK->NotePnt->NoteType;
  909.   LINK->Beaming = true;
  910.   WITH->NoNotes = 1;
  911.   WITH->Numb = BeamIndex;
  912.   BeamIndex++;
  913.   sprintf(STR1, "Starting beam %3d at note %3d of type %3d",
  914.       WITH->Numb,LINK->NotePnt->NoteVal,(int)WITH->NoteType);
  915.   WriteDebugInfo(STR1);
  916. }
  917.  
  918. /*--------------------*/
  919.  Void EndBeam(LINK)
  920. struct LOC_BeamFind *LINK;
  921. {
  922.   /*--------------------*/
  923.   unsigned short mn, i;
  924.   uchar cnt, BPnt, max, min;
  925.   NoteRecord *N, *P;
  926.   boolean GoOn;
  927.   BeamRecord *WITH;
  928.   unsigned short FORLIM;
  929. /*  Char STR1[256]; */
  930.  
  931.   WITH = &LINK->ThisTrack->BeamArray[LINK->BeamPnt - 1];
  932.  
  933.   LINK->Beaming = false;
  934.   WITH->Chain2Next = false;
  935.   mn = 0;
  936.   max = 0;
  937.   min = 127;
  938.   cnt = 0;
  939.   BPnt = LINK->BeamPnt;
  940.   /* Pitch and slope should be determined over all chained beams */
  941.  
  942.   /* first, from the top find the first beam which has CHain2Next flag set */
  943.   GoOn = false;
  944.   if (BPnt > 1)
  945.     BPnt--;
  946.   while (!GoOn) {
  947.     if (LINK->ThisTrack->BeamArray[BPnt - 1].Chain2Next ==true && BPnt > 1)
  948.       BPnt--;
  949.     else {
  950.       if (!LINK->ThisTrack->BeamArray[BPnt - 1].Chain2Next) {
  951.     if (BPnt < LINK->BeamPnt)
  952.       BPnt++;
  953.       }
  954.       GoOn = true;
  955.     }
  956.   }
  957.  
  958.   FORLIM = LINK->BeamPnt;
  959.   /* The first Chain2Next Beam is pointed to by BPnt */
  960.   /* We now have to process all the notes in the beams until BPnt=BeamPnt */
  961.  
  962.   for (i = BPnt - 1; i < FORLIM; i++) {
  963.     WITH = &LINK->ThisTrack->BeamArray[i];   /* With */
  964.     N = WITH->StartNote;
  965.     NextNote(WITH->EndNote, &P);
  966.     do {
  967.       /*If NOT N^.ChordNote Then*/
  968.       switch (N->Event) {
  969.  
  970.       case NOTEON:
  971.       case NOTEOFF:
  972.     mn += N->NoteVal;
  973.     cnt++;
  974.     if (N->NoteVal > max)
  975.       max = N->NoteVal;
  976.     if (N->NoteVal < min)
  977.       min = N->NoteVal;
  978.     break;
  979.       }/* case */
  980.       NextNote(N, &N);
  981.     } while (N != P);
  982.   }  /* For */
  983.  
  984.   WITH = &LINK->ThisTrack->BeamArray[BPnt - 1];
  985.       /* with thistrack.beamarray */
  986.  
  987.   /* mn,cnt,Max and Min now have values  calculated over all Chained beams */
  988.   /* We now have to fill the first beam record (Bpnt) with these values */
  989.  
  990.   /* This routine now does not take in account the orient of the note   */
  991.   /* itself set by FindNotes and ChordFind. Look at this again...       */
  992.   /* When handling chords, the mean only sees single notes of the chord.*/
  993.   /* So that messes up a lot. */
  994.  
  995.   mn /= cnt;
  996.   switch (LINK->ThisTrack->Clef) {
  997.  
  998.   case VIOLIN:
  999.     if (mn < 70)
  1000.       WITH->Orient = UP;
  1001.     else
  1002.       WITH->Orient = DOWN;
  1003.     break;
  1004.  
  1005.   case BASS:
  1006.     if (mn < 52)
  1007.       WITH->Orient = UP;
  1008.     else
  1009.       WITH->Orient = DOWN;
  1010.     break;
  1011.   }
  1012.   if (WITH->Orient == UP)
  1013.     WITH->Pitch = max;
  1014.   else
  1015.     WITH->Pitch = min;
  1016.  
  1017.   if (WITH->EndNote->NoteVal > WITH->StartNote->NoteVal)
  1018.     WITH->Slope = (max - min) / cnt;
  1019.   else
  1020.     WITH->Slope = -((max - min) / cnt);
  1021.   /* WriteDebugInfo('Beam '+B2S(BeamPnt)+' has pitch '+B2S(Pitch)+
  1022.                  ',max='+B2S(max)+' min='+B2S(min)); */
  1023.   if (WITH->Orient == UP) {
  1024.     sprintf(STR1, "Ending beam %3d, beam is UP", WITH->Numb);
  1025.     WriteDebugInfo(STR1);
  1026.   } else {
  1027.     sprintf(STR1, "Ending beam %3d, beam is DOWN", WITH->Numb);
  1028.     WriteDebugInfo(STR1);
  1029.   }
  1030.   FORLIM = LINK->BeamPnt;
  1031.   /* Now Pitch,Orient & Slope must be copied to all Chained beams */
  1032.   for (i = BPnt + 1; i <= FORLIM; i++) {
  1033.     LINK->ThisTrack->BeamArray[i - 1].Orient =
  1034.       LINK->ThisTrack->BeamArray[i - 2].Orient;
  1035.     LINK->ThisTrack->BeamArray[i - 1].Slope =
  1036.       LINK->ThisTrack->BeamArray[i - 2].Slope;
  1037.     LINK->ThisTrack->BeamArray[i - 1].Pitch =
  1038.       LINK->ThisTrack->BeamArray[i - 2].Pitch;
  1039.   }
  1040.  
  1041.   LINK->BeamPnt++;
  1042.   if (LINK->BeamPnt > MAXBEAMS)
  1043.     ErrorExit(18L);
  1044. }
  1045.  
  1046. /*--------------------*/
  1047.  Void CancelBeam(LINK)
  1048. struct LOC_BeamFind *LINK;
  1049. {
  1050.   /*--------------------*/
  1051.   BeamRecord *WITH;
  1052. /*  Char STR1[256], STR2[256]; */
  1053.  
  1054.   LINK->Beaming = false;
  1055.   WITH = &LINK->ThisTrack->BeamArray[LINK->BeamPnt - 1];
  1056.   WITH->StartNote = NULL;
  1057.   WITH->EndNote = NULL;
  1058.   WITH->NoNotes = 0;
  1059.   sprintf(STR1, "Canceling beam %3d at note %3d",
  1060.       WITH->Numb,LINK->NotePnt->NoteVal);
  1061.   WriteDebugInfo(STR1);
  1062. }
  1063.  
  1064. /*--------------------*/
  1065.  Void QuitBeam(LINK)
  1066. struct LOC_BeamFind *LINK;
  1067. {
  1068.   /*--------------------*/
  1069.   /* Close up the beams. Cancel Beam only if previous beam */
  1070.   /* has Chain2Next flag not set OR if BeamPnt=1 */
  1071.   TrackRecord *WITH;
  1072.  
  1073.   WITH = LINK->ThisTrack;
  1074.   if (WITH->BeamArray[LINK->BeamPnt - 1].NoNotes != 1) {
  1075.     EndBeam(LINK);
  1076.     return;
  1077.   }
  1078.   if (LINK->BeamPnt == 1) {
  1079.     CancelBeam(LINK);
  1080.     return;
  1081.   }
  1082.   if (WITH->BeamArray[LINK->BeamPnt - 2].Chain2Next)
  1083.     EndBeam(LINK);
  1084.   else
  1085.     CancelBeam(LINK);
  1086. }  /* QuitBeam */
  1087.  
  1088. /*--------------------*/
  1089.  Void Add2Beam(LINK)
  1090. struct LOC_BeamFind *LINK;
  1091. {
  1092.   /*--------------------*/
  1093.   BeamRecord *WITH;
  1094.  
  1095.   WITH = &LINK->ThisTrack->BeamArray[LINK->BeamPnt - 1];
  1096.   WITH->NoNotes++;
  1097.   WITH->EndNote = LINK->NotePnt;
  1098. }
  1099.  
  1100. /*--------------------------*/
  1101.  Void CreateUpChainBeam(LINK)
  1102. struct LOC_BeamFind *LINK;
  1103. {
  1104.   /*--------------------------*/
  1105.   BeamRecord *WITH;
  1106. /*  Char STR1[256], STR2[256]; */
  1107.  
  1108.   WITH = &LINK->ThisTrack->BeamArray[LINK->BeamPnt - 1];
  1109.   WITH->Chain2Next = true;
  1110.   WITH->EndNote = LINK->NotePnt;
  1111.   LINK->BeamPnt++;
  1112.   if (LINK->BeamPnt > MAXBEAMS)
  1113.     ErrorExit(18L);
  1114.   WITH = &LINK->ThisTrack->BeamArray[LINK->BeamPnt - 1];
  1115.   WITH->StartNote = LINK->NotePnt;
  1116.   WITH->EndNote = LINK->NotePnt;
  1117.   WITH->NoteType = LINK->NotePnt->NoteType;
  1118.   WITH->Numb = BeamIndex - 1;
  1119.   LINK->Beaming = true;
  1120.   WITH->NoNotes = 1;
  1121.   sprintf(STR1, "Chain  beam %3d at note %3d to type %3d",
  1122.       WITH->Numb,LINK->NotePnt->NoteVal,(int)WITH->NoteType);
  1123.   WriteDebugInfo(STR1);
  1124. }  /* CreateUpChainBeam */
  1125.  
  1126. /*--------------------------*/
  1127.  Void CreateDnChainBeam(LINK)
  1128. struct LOC_BeamFind *LINK;
  1129. {
  1130.   /*--------------------------*/
  1131.   BeamRecord *WITH;
  1132. /*  Char STR1[256], STR2[256]; */
  1133.  
  1134.   WITH = &LINK->ThisTrack->BeamArray[LINK->BeamPnt - 1];
  1135.   WITH->Chain2Next = true;
  1136.   LINK->BeamPnt++;
  1137.   if (LINK->BeamPnt > MAXBEAMS)
  1138.     ErrorExit(18L);
  1139.   WITH = &LINK->ThisTrack->BeamArray[LINK->BeamPnt - 1];
  1140.   WITH->StartNote = LINK->NotePnt;
  1141.   WITH->EndNote = LINK->NotePnt;
  1142.   WITH->NoteType = LINK->NotePnt->NoteType;
  1143.   WITH->Numb = BeamIndex - 1;
  1144.   LINK->Beaming = true;
  1145.   WITH->NoNotes = 1;
  1146.   sprintf(STR1, "Chain beam %3d at note %3d to type %3d",
  1147.       WITH->Numb,LINK->NotePnt->NoteVal,(int)WITH->NoteType);
  1148.   WriteDebugInfo(STR1);
  1149. }  /* CreateDnChainBeam */
  1150.  
  1151.  
  1152. /******************************************************/
  1153.  Void BeamFind(ThisTrack_)
  1154. TrackRecord *ThisTrack_;
  1155. {
  1156.   /******************************************************/
  1157.   struct LOC_BeamFind V;
  1158.   NoteRecord *FirstPnt;
  1159.   TrackRecord *WITH;
  1160. /*  Char STR1[256], STR2[256]; */
  1161.  
  1162.  
  1163.   V.ThisTrack = ThisTrack_;
  1164.   WriteDebugInfo("Starting BeamFind");
  1165.   V.BeamPnt = 1;
  1166.   V.Beaming = false;
  1167.  
  1168.   WITH = V.ThisTrack;   /* with thistrack */
  1169.  
  1170.  
  1171.   FirstNote(WITH->NoteList, &V.NotePnt);
  1172.   FirstPnt = NULL;   /* prevent early termination */
  1173.  
  1174.   while (V.NotePnt != FirstPnt) {  /* while */
  1175.     FirstNote(WITH->NoteList, &FirstPnt);
  1176.     switch (V.NotePnt->Event) {
  1177.  
  1178.     case NOTEON:
  1179.     case NOTEOFF:
  1180.       if (!V.NotePnt->ChordNote) {   /* exclude non-spacing notes */
  1181.     sprintf(STR1, "Note %3d is of type %3d",
  1182.         V.NotePnt->NoteVal,(int)V.NotePnt->NoteType);
  1183.     WriteDebugInfo(STR1);
  1184.     if (V.Beaming) {
  1185.       switch (WITH->BeamArray[V.BeamPnt - 1].NoteType) {
  1186.  
  1187.       case CPPP:
  1188.       case CPP:
  1189.       case C3:
  1190.       case CP:
  1191.       case C:
  1192.         switch (V.NotePnt->NoteType) {
  1193.  
  1194.         case CC3:
  1195.         case CCP:
  1196.         case CC:
  1197.         case CCC3:
  1198.         case CCCP:
  1199.         case CCC:
  1200.         case CCCC3:
  1201.         case CCCCP:
  1202.         case CCCC:
  1203.           CreateUpChainBeam(&V);
  1204.           break;
  1205.  
  1206.         case CPPP:
  1207.         case CPP:
  1208.         case C3:
  1209.         case CP:
  1210.         case C:
  1211.           Add2Beam(&V);
  1212.           break;
  1213.  
  1214.         default:
  1215.           QuitBeam(&V);
  1216.           break;
  1217.         }
  1218.         break;
  1219.  
  1220.       case CC3:
  1221.       case CCP:
  1222.       case CC:
  1223.         switch (V.NotePnt->NoteType) {
  1224.  
  1225.         case CPPP:
  1226.         case CPP:
  1227.         case C3:
  1228.         case CP:
  1229.         case C:
  1230.           CreateDnChainBeam(&V);
  1231.           break;
  1232.  
  1233.         case CCC3:
  1234.         case CCCP:
  1235.         case CCC:
  1236.         case CCCC3:
  1237.         case CCCCP:
  1238.         case CCCC:
  1239.           CreateUpChainBeam(&V);
  1240.           break;
  1241.  
  1242.         case CC3:
  1243.         case CCP:
  1244.         case CC:
  1245.           Add2Beam(&V);
  1246.           break;
  1247.  
  1248.         default:
  1249.           QuitBeam(&V);
  1250.           break;
  1251.         }
  1252.         break;
  1253.  
  1254.       case CCC3:
  1255.       case CCCP:
  1256.       case CCC:
  1257.         switch (V.NotePnt->NoteType) {
  1258.  
  1259.         case CPPP:
  1260.         case CPP:
  1261.         case C3:
  1262.         case CP:
  1263.         case C:
  1264.         case CCPP:
  1265.         case CC3:
  1266.         case CCP:
  1267.         case CC:
  1268.           CreateDnChainBeam(&V);
  1269.           break;
  1270.  
  1271.         case CCCC3:
  1272.         case CCCCP:
  1273.         case CCCC:
  1274.           CreateUpChainBeam(&V);
  1275.           break;
  1276.  
  1277.         case CCC3:
  1278.         case CCCP:
  1279.         case CCC:
  1280.           Add2Beam(&V);
  1281.           break;
  1282.  
  1283.         default:
  1284.           QuitBeam(&V);
  1285.           break;
  1286.         }
  1287.         break;
  1288.  
  1289.       case CCCC3:
  1290.         switch (V.NotePnt->NoteType) {
  1291.  
  1292.         case CCCC3:
  1293.           Add2Beam(&V);
  1294.           break;
  1295.  
  1296.         default:
  1297.           if ((long)V.NotePnt->NoteType >= (long)CPPP &&
  1298.           (long)V.NotePnt->NoteType <= (long)CCC)
  1299.         CreateDnChainBeam(&V);
  1300.           else
  1301.         QuitBeam(&V);
  1302.           break;
  1303.         }
  1304.         break;
  1305.  
  1306.       default:
  1307.         QuitBeam(&V);
  1308.         break;
  1309.       }/* Case under If Beaming */
  1310.  
  1311.     } else {  /* not Beaming */
  1312.       if ((long)V.NotePnt->NoteType > (long)CPP)
  1313.         StartBeam(&V);
  1314.     }  /* not Beaming */
  1315.  
  1316.       }  /* NOTEON,NOTEOFF */
  1317.       break;
  1318.     }/* CASE N^.Event OF */
  1319.     NextNote(V.NotePnt, &V.NotePnt);
  1320.   }  /* WHILE */
  1321.   if (V.Beaming)
  1322.     QuitBeam(&V);
  1323.  
  1324.   WriteDebugInfo("BeamFind Ready");
  1325.  
  1326.  
  1327. }  /* BeamFind */
  1328.  
  1329.  
  1330.  
  1331. /**********************************************/
  1332.  Void InitFilePosns(N)
  1333.  long N;
  1334. {
  1335.   /**********************************************/
  1336.   uchar i, dummy;
  1337.   long cnt, NoOfBytes;
  1338.   Char TmpStr[256];
  1339. /*
  1340.   Char STR1[256];
  1341.   Char STR2[256];
  1342. */
  1343.   TrackRecord *WITH;
  1344.   fpos_t OldPos;
  1345.   char *ptr;
  1346.   i = 1;
  1347.   fgetpos(MidiFile,&OldPos);
  1348.   
  1349.   do {
  1350.  
  1351.     ReadString(TmpStr, &HlpFilRec, 4L);
  1352.     sprintf(STR1, " Found start of track %3d with name:%s",i,TmpStr);
  1353.     WriteDebugInfo(STR1);
  1354.     NoOfBytes = ReadLongInt(&HlpFilRec);
  1355.     sprintf(STR1, "%3ld bytes in this track", NoOfBytes);
  1356.     WriteDebugInfo(STR1);
  1357.     sprintf(STR1,"FilePos : %ld",GetFilePos(&HlpFilRec));
  1358.     WriteDebugInfo(STR1);
  1359.     WITH = &TrackArray[i - 1];
  1360.     /* Copy the file info stuff into the currentr track file info */
  1361.     WITH->FilRec.FilePosition = HlpFilRec.FilePosition;
  1362.     memmove(WITH->FilRec.ReadBuf, HlpFilRec.ReadBuf,sizeof(BufType));
  1363.     WITH->EndOfTrackRead = false;
  1364.     WITH->FilRec.BytesProcessed = 0;
  1365.     WITH->FilRec.BufSemaphore = HlpFilRec.BufSemaphore;
  1366.     /* this is wrong, new BufPoint should be pointing in other buffer !!!
  1367.     WITH->FilRec.BufPoint = HlpFilRec.BufPoint; */
  1368.     ptr=HlpFilRec.ReadBuf;
  1369.     WITH->FilRec.BufPoint = WITH->FilRec.ReadBuf;
  1370.     while (ptr!=HlpFilRec.BufPoint){
  1371.       ptr++;
  1372.       WITH->FilRec.BufPoint++;
  1373.     }
  1374.     WITH->FilRec.LastBlockRead = HlpFilRec.LastBlockRead;
  1375.     SafetyCounter = 0;
  1376.     memset((&WITH->Curtime), 0, sizeof(MeasureTime));
  1377.     memset((&WITH->OldTime), 0, sizeof(MeasureTime));
  1378.     for (cnt = 1; cnt <= NoOfBytes; cnt++)
  1379.       dummy = ReadByte(&HlpFilRec);
  1380.     sprintf(STR1,"FilePos : %ld",GetFilePos(&HlpFilRec));
  1381.     WriteDebugInfo(STR1);
  1382.     i++;
  1383.   } while (i != N + 1);
  1384.   fsetpos(MidiFile,&OldPos);
  1385. }  /* InitFilePosns */
  1386.  
  1387. /**********************************************/
  1388.  boolean AllTracksRead(N)
  1389. long N;
  1390. {
  1391.   /**********************************************/
  1392.   boolean b;
  1393.   long i;
  1394.  
  1395.   b = true;
  1396.   for (i = 0; i < N; i++) {
  1397.     if (!EndOfTrackReached(&TrackArray[i]))
  1398.       b = false;
  1399.   }
  1400.   return b;
  1401. }
  1402.  
  1403. /*  variables for InitFileDebug: 
  1404. struct LOC_InitFileDebug {
  1405.   uchar FilesSel;
  1406. } ; */
  1407.  
  1408. /*--------------------------------------------------------------*/
  1409. Void SplitExtension(ThisFile,path,ext)
  1410. char *ThisFile,*path,*ext;
  1411. /*--------------------------------------------------------------*/
  1412. {
  1413. Char *pos;
  1414.  
  1415. pos=strrchr(ThisFile,'.');
  1416. if (pos==NULL)
  1417.    strcpy(path,ThisFile);
  1418. else{
  1419.    strncpy(path,ThisFile,strlen(ThisFile)-strlen(pos));
  1420.    strncpy(ext,pos,4);
  1421.    }
  1422. }
  1423.  
  1424. /*--------------------------------------------------------------*/
  1425.  Void ReadFileName(ThisFile, path, LINK)
  1426. FileNameType *ThisFile;
  1427. Char *path;
  1428. struct LOC_InitFileDebug *LINK;
  1429. {
  1430.   /*--------------------------------------------------------------*/
  1431.   Char *p;
  1432.   p=strrchr(path,'.');
  1433.   if (p==NULL) {
  1434.     if (LINK->FilesSel == 0)
  1435.       strcat(path, ".MID");
  1436.     else
  1437.       strcat(path, ".TEX");
  1438.   }
  1439.   /*
  1440.   _fullpath(ThisFile->p,path,80);
  1441.   _splitpath(ThisFile->p, ThisFile->r, ThisFile->d, ThisFile->n, ThisFile->e);
  1442.   */
  1443.   strcpy(ThisFile->p, path);
  1444.   SplitExtension(ThisFile->p,ThisFile->n,ThisFile->e);
  1445.   LINK->FilesSel++;
  1446. }  /* ReadFileName */
  1447.  
  1448.  
  1449. /**********************************************/
  1450.  Void InitFileDebug(P_argc,P_argv)
  1451.  int P_argc;
  1452.  char *P_argv[];
  1453. {
  1454.   /**********************************************/
  1455.   struct LOC_InitFileDebug V;
  1456.   uchar Pcnt, j;
  1457.   Char *PS,*p,*end;                /*  ,*S;   *S is not used */
  1458.   long Sint, Serr;
  1459.   
  1460. /*   Char STR1[256], STR2[256]; */
  1461.  
  1462. if ((PS = (char *) malloc(80*sizeof(char))) == NULL)
  1463.     { printf("allocation error for PS - aborting\n");
  1464.       exit(1);
  1465.     }
  1466.   V.FilesSel = 0;
  1467.   DebugOut = NODEB;
  1468.   Debug = false;
  1469.  
  1470.   for (Pcnt = 1; Pcnt < P_argc; Pcnt++) {
  1471.     /* WriteLn('Paramstring=',ParamStr(PCnt)); */
  1472.     /* printf("%s\n",P_argv[Pcnt]); */
  1473.     
  1474.     strcpy(PS, P_argv[Pcnt]);
  1475.     sprintf(STR1, "%.1s", PS);
  1476.     if (!strcmp(STR1, "-")) {
  1477.  
  1478.       sprintf(STR1, "%.2s", PS);
  1479.       if (!strcmp(STR1, "-?"))
  1480.     ErrorExit(0L);
  1481.  
  1482. #ifdef ST
  1483.       sprintf(STR1, "%.2s", PS);
  1484.       if (!strcmp(STR1, "-x"))
  1485.     BatchProcessing = true;
  1486.       sprintf(STR1, "%.2s", PS);
  1487. #endif
  1488.  
  1489.       sprintf(STR1, "%.2s", PS);
  1490.       if (!strcmp(STR1, "-i")) {  /* determine instrument staffs */
  1491.     if (ninstruments > 0) {ErrorExit(14L);};
  1492.     ninstruments++;
  1493.     if (strlen(PS) < 3){ ErrorExit(15L);};
  1494.     
  1495.     p=strtok((PS+2), ",");
  1496.     while (p != NULL) {
  1497.       Sint = strtol(p,&end,10);
  1498.       TrackArray[Sint - 1].Instrument = true;
  1499.       nTracksInInstr++;
  1500.       sprintf(STR1, "Track :%3ld is part of an instrument",Sint);
  1501.       WriteDebugInfo(STR1);
  1502.       p=strtok(NULL, ",");
  1503.     }
  1504.       }  /* if switch='-i' */
  1505.  
  1506.       sprintf(STR1, "%.2s", PS);
  1507.       if (!strcmp(STR1, "-f")) {  /* force zero beams for these staffs */
  1508.     
  1509.     p=strtok((PS+2), ",");
  1510.     while (p != NULL) {
  1511.       Sint = strtol(p,&end,10);
  1512.       TrackArray[Sint - 1].ForceZeroBeams= true;
  1513.       sprintf(STR1, "Track :%3ld has beam slope forced to zero",Sint);
  1514.       WriteDebugInfo(STR1);
  1515.       p=strtok(NULL, ",");
  1516.     }
  1517.       }  /* if switch='-f' */
  1518.  
  1519.       sprintf(STR1, "%.2s", PS);
  1520.       if (!strcmp(STR1, "-h")) {  /* change horizontal size */
  1521.     
  1522.     if ((PS+2) != NULL) { /* wat doet deze voorwaarde */
  1523.       Sint = strtol((PS+2),&end,10);
  1524.       ScoreWidth = Sint;
  1525.       SizingChanged = true;
  1526.       sprintf(STR1, "Changing scorewidth from default to %3ld",ScoreWidth);
  1527.       WriteDebugInfo(STR1);
  1528.     }
  1529.       }  /* if switch='-h' */
  1530.  
  1531.       sprintf(STR1, "%.2s", PS);
  1532.       if (!strcmp(STR1, "-v")) {  /* change vertical size */
  1533.     
  1534.     if ((PS+2) != NULL) {
  1535.       Sint = strtol((PS+2),&end,10);
  1536.       ScoreHeight = Sint;
  1537.       SizingChanged = true;
  1538.       sprintf(STR1, "Changing scoreheight from default to %3ld",ScoreHeight);
  1539.       WriteDebugInfo(STR1);
  1540.     }
  1541.       }  /* if switch='-v' */
  1542.  
  1543.       sprintf(STR1, "%.2s", PS);
  1544.       if (!strcmp(STR1, "-e")) {  /* change elemskip size */
  1545.     
  1546.     if ((PS+2) != NULL) {
  1547.       Sint = strtol((PS+2),&end,10);
  1548.       ElemSkip = (long)(Sint * PT);
  1549.       SizingChanged = true;
  1550.       sprintf(STR1, "Changing Elemskip from default to %3ld",ElemSkip);
  1551.       WriteDebugInfo(STR1);
  1552.     }
  1553.       }  /* if switch='-e' */
  1554.  
  1555.        sprintf(STR1, "%.2s", PS);
  1556.        if (!strcmp(STR1, "-m")) {  /* change magnitude of score */
  1557.     
  1558.     if ((PS+2) != NULL) {
  1559.       Sint = strtol((PS+2),&end,10);
  1560.       switch (Sint) {
  1561.       case 20:
  1562.         MusicSize = 20;
  1563.         LineHeight = 160;
  1564.         ScoreSep = 20;
  1565.         Indent = 115;
  1566.         CumLength = 215;
  1567.         BarIndent = 40;
  1568.         ElemSkip = (long)(10 * PT);
  1569.         break;
  1570.  
  1571.       case 16:
  1572.         MusicSize = 16;
  1573.         LineHeight = 125;
  1574.         ScoreSep = 40;
  1575.         Indent = 90;
  1576.         CumLength = 190;
  1577.         BarIndent = 30;
  1578.         ElemSkip = (long)(8 * PT);
  1579.         break;
  1580.  
  1581.       default:
  1582.         ErrorExit(20L);
  1583.         break;
  1584.       }/* case */
  1585.       SizingChanged = true;
  1586.       sprintf(STR1, "Changing magnitude from default to %3ld",Sint);
  1587.       WriteDebugInfo(STR1);
  1588.     }
  1589.       }  /* if switch='-m' */
  1590.  
  1591.       sprintf(STR1, "%.2s", PS);
  1592.       if (!strcmp(STR1, "-k")) {  /* change keysign of score */
  1593.     
  1594.     if ((PS+2) != NULL) {
  1595.       Sint = strtol((PS+2),&end,10);
  1596.       if (Sint >= -8 && Sint <= 8)
  1597.         PieceContr.KeySign = Sint;
  1598.       else
  1599.         ErrorExit(21L);
  1600.       sprintf(STR1, "Changing keysign to %3ld",Sint);
  1601.       WriteDebugInfo(STR1);
  1602.     }
  1603.       }  /* if switch='-k' */
  1604.  
  1605.       sprintf(STR1, "%.2s", PS);
  1606.       if (!strcmp(STR1, "-q")) {  /* quantization timing */
  1607.     
  1608.     if ((PS+2) != NULL) {
  1609.       Sint = strtol((PS+2),&end,10);
  1610.       if (Sint <= 64 && Sint > 0) {
  1611.         Quantizing = true;
  1612.         QuantTime = Sint;
  1613.       } else
  1614.         ErrorExit(13L);
  1615.       sprintf(STR1, "Using quantization %3ld",Sint);
  1616.       WriteDebugInfo(STR1);
  1617.     } 
  1618.       }  /* if switch='-q' */
  1619.  
  1620.       sprintf(STR1, "%.2s", PS);
  1621.       if (!strcmp(STR1, "-b")) {  /* force zero beams for these staffs */
  1622.     
  1623.     p=strtok((PS+2), ",");
  1624.     while (p != NULL) {
  1625.       Sint = strtol(p,&end,10);
  1626.       TrackArray[Sint - 1].Clef = BASS;
  1627.       sprintf(STR1, "Track :%3ld notated with bass clef", Sint);
  1628.       WriteDebugInfo(STR1);
  1629.       p=strtok(NULL, ",");
  1630.     }  
  1631.       }  /* if switch='-b' */
  1632.  
  1633.       sprintf(STR1, "%.3s", PS);
  1634.       if (!strcmp(STR1, "-a1")) {  /* determine ALTO1 clefs */
  1635.     
  1636.     p=strtok((PS+3),",");
  1637.     while (p!= NULL) {
  1638.       Sint = strtol(p,&end,10);
  1639.       if (Sint > 0)
  1640.         TrackArray[Sint - 1].Clef = ALTO1;
  1641.       else
  1642.         ErrorExit(22L);
  1643.       sprintf(STR1, "Track :%3ld notated with ALTO1 clef", Sint);
  1644.       WriteDebugInfo(STR1);
  1645.       p=strtok(NULL, ",");
  1646.     }
  1647.       }  /* if switch='-a1' */
  1648.  
  1649.       sprintf(STR1, "%.3s", PS);
  1650.       if (!strcmp(STR1, "-a2")) {  /* determine ALTO2 clefs */
  1651.     
  1652.     p=strtok((PS+3),",");
  1653.     while (p!= NULL) {
  1654.       Sint = strtol(p,&end,10);
  1655.       if (Sint > 0)
  1656.         TrackArray[Sint - 1].Clef = ALTO2;
  1657.       else
  1658.         ErrorExit(22L);
  1659.       sprintf(STR1, "Track :%3ld notated with ALTO2 clef", Sint);
  1660.       WriteDebugInfo(STR1);
  1661.       p=strtok(NULL, ",");
  1662.     }
  1663.       }  /* if switch='-a2' */
  1664.  
  1665.       sprintf(STR1, "%.3s", PS);
  1666.       if (!strcmp(STR1, "-a3")) {  /* determine ALTO3 clefs */
  1667.     
  1668.     p=strtok((PS+3),",");
  1669.     while (p!= NULL) {
  1670.       Sint = strtol(p,&end,10);
  1671.       if (Sint > 0)
  1672.         TrackArray[Sint - 1].Clef = ALTO3;
  1673.       else
  1674.         ErrorExit(22L);
  1675.       sprintf(STR1, "Track :%3ld notated with ALTO3 clef", Sint);
  1676.       WriteDebugInfo(STR1);
  1677.       p=strtok(NULL, ",");
  1678.     }
  1679.       }  /* if switch='-a3' */
  1680.  
  1681.       sprintf(STR1, "%.3s", PS);
  1682.       if (!strcmp(STR1, "-a4")) {  /* determine ALTO4 clefs */
  1683.     
  1684.     p=strtok((PS+3),",");
  1685.     while (p!= NULL) {
  1686.       Sint = strtol(p,&end,10);
  1687.       if (Sint > 0)
  1688.         TrackArray[Sint - 1].Clef = ALTO4;
  1689.       else
  1690.         ErrorExit(22L);
  1691.       sprintf(STR1, "Track :%3ld notated with ALTO4 clef", Sint);
  1692.       WriteDebugInfo(STR1);
  1693.       p=strtok(NULL, ",");
  1694.     }
  1695.       }  /* if switch='-a4' */
  1696.  
  1697.  
  1698.       sprintf(STR1, "%.2s", PS);
  1699.       if (!strcmp(STR1, "-o")) {  /* order staffs */
  1700.     
  1701.     p=strtok((PS+2), ",");
  1702.     while (p != NULL ) {   /* now pointing at last item in orderarray */
  1703.         Sint = strtol(p,&end,10);
  1704.         TrackOrder[OrderIndex - 1] = Sint;
  1705.         sprintf(STR1, "Ordering MIDI Track :%3ld at Staff %3ld",Sint,OrderIndex);
  1706.         WriteDebugInfo(STR1);
  1707.         OrderIndex++;
  1708.         p=strtok(NULL,",");
  1709.     }
  1710.     OrderIndex--;
  1711.       }  /* if switch='-o' */
  1712.  
  1713.       sprintf(STR1, "%.2s", PS);
  1714.       if (!strcmp(STR1, "-s")) {  /* skipping tracks */
  1715.     
  1716.     p=strtok((PS+2), ",");
  1717.     while (p != NULL ) {   /* now pointing at last item in orderarray */
  1718.         Sint = strtol(p,&end,10);
  1719.         if (Sint == 1) {
  1720.           TrackArray[Sint - 1].Skip = false;
  1721.           NoOfSkips--;
  1722.         } else {
  1723.           TrackArray[Sint - 1].Skip++;
  1724.           NoOfSkips++;
  1725.         }
  1726.         sprintf(STR1, "Skipping Track :%3ld", Sint);
  1727.         WriteDebugInfo(STR1);
  1728.         p=strtok(NULL,",");
  1729.       }
  1730.       }  /* if switch='-s' */
  1731.  
  1732.  
  1733.       sprintf(STR1, "%.2s", PS);
  1734.       if (!strcmp(STR1, "-p")) {  /* part timing */
  1735.     
  1736.     if ((PS+2) != NULL ) {   /* now pointing at last item in orderarray */
  1737.         Sint = strtol((PS+2),&end,10);
  1738.         switch (Sint) {
  1739.  
  1740.         case 1:
  1741.         case 2:
  1742.         case 4:
  1743.         case 8:
  1744.         case 16:
  1745.         case 32:
  1746.           PieceContr.PartType = Sint;
  1747.           sprintf(STR1, "Part Timing =%3ld", Sint);
  1748.           WriteDebugInfo(STR1);
  1749.           PieceContr.PartOverRule = true;
  1750.           break;
  1751.  
  1752.         default:
  1753.           ErrorExit(12L);
  1754.           break;
  1755.         }
  1756.         sprintf(STR1, "Part time :%3ld", Sint);
  1757.         WriteDebugInfo(STR1);
  1758.       }
  1759.       }  /* if switch='-p' */
  1760.     
  1761.     sprintf(STR1, "%.2s", PS);
  1762.       if (!strcmp(STR1, "-d")) {
  1763.     
  1764.     if (!strcmp((PS+2), "FILE") || !strcmp((PS+2), "file")) {
  1765.  
  1766.       DebugFile=fopen(DebugFileName.p,"w");
  1767.       if (DebugFile == NULL)
  1768.         DebugFile = tmpfile();
  1769.       /*
  1770.       else
  1771.         rewind(DebugFile);
  1772.       */
  1773. /*
  1774.       DebBuf = (uchar *)malloc(sizeof(BufType));
  1775.       if (DebBuf==NULL) ErrorExit(9L);
  1776.       if (setvbuf(DebugFile, DebBuf , _IOFBF, sizeof(BufType))!=0)
  1777.           {ErrorExit(9L);}
  1778. */
  1779.       DebugFileOpened = true;
  1780.       DebugOut = DEBFILE;
  1781.       Debug = true;
  1782.     }
  1783.     if (!strcmp((PS+2), "PRINTER")) {
  1784.       DebugOut = PRINT;
  1785.       Debug = true;
  1786.     }
  1787.     if (!strcmp((PS+2), "SCREEN")) {
  1788.       DebugOut = SCREEN;
  1789.       Debug = true;
  1790.     }
  1791.       } /* if -d switch */
  1792.     }  /* If this parameter is a switch */
  1793.     else {  /* this parameter is not a switch */
  1794.       if (V.FilesSel == 0) {
  1795.     ReadFileName(&MidiFileName, PS, &V);
  1796.     memcpy(&DebugFileName,&MidiFileName,sizeof(FileNameType));
  1797.     strcpy(DebugFileName.e, ".MLG");
  1798.     sprintf(DebugFileName.p, "%s%s",DebugFileName.n, DebugFileName.e);
  1799.       } else
  1800.     ReadFileName(&TeXFileName, PS, &V);
  1801.     }  /* else not a switch */
  1802.   }  /* for next loop */
  1803.   
  1804.   switch (V.FilesSel) {
  1805.      case 0 :  ErrorExit(1L); break;
  1806.      case 1 :  /* there was no TeXFilename selected */
  1807.            memcpy(&TeXFileName,&MidiFileName,sizeof(FileNameType));
  1808.            strcpy(TeXFileName.e, ".TEX");
  1809.            sprintf(TeXFileName.p, "%s%s", TeXFileName.n, TeXFileName.e);
  1810.            break;
  1811.      }
  1812.  
  1813.   if (MidiFile != NULL)
  1814.     MidiFile = freopen(MidiFileName.p, "rb", MidiFile);
  1815.   else
  1816.     MidiFile = fopen(MidiFileName.p, "rb");
  1817.  
  1818.   if (MidiFile == NULL)
  1819.     {
  1820. #ifdef __TURBOC__
  1821.      _doserrno=0; /* prevent DOS error */
  1822. #endif
  1823.      ErrorExit(1L);}
  1824.   else
  1825.     rewind(MidiFile);
  1826.  
  1827.   if (TexFile != NULL)
  1828.     TexFile = freopen(TeXFileName.p, "w", TexFile);
  1829.   else
  1830.     TexFile = fopen(TeXFileName.p, "w");
  1831.  
  1832.   if (TexFile == NULL)  ErrorExit(25L);
  1833.  
  1834.   if (TexFile == NULL)
  1835.     TexFile = tmpfile();
  1836.   /*
  1837.   else
  1838.     rewind(TexFile);
  1839.   */
  1840. /*
  1841.   TexBuf = (uchar *)malloc(sizeof(BufType));
  1842.   if (TexBuf==NULL) ErrorExit(9L);
  1843.   if (setvbuf(TexFile, TexBuf , _IOFBF, sizeof(BufType))!=0)
  1844.     {ErrorExit(9L);}
  1845. */
  1846.  
  1847.   MidiFileOpened = true;
  1848.   printf("Translating %s into ",MidiFileName.p);
  1849.   printf("%s\n", TeXFileName.p);
  1850.   WriteDebugInfo("***********************************************");
  1851.   sprintf(STR1, "*   Midi2TeX translator %s *",VERSION);
  1852.   WriteDebugInfo(STR1);
  1853.   WriteDebugInfo("*                   by                        *");
  1854.   WriteDebugInfo("*       Hans Kuykens, Ad Verbruggen           *");
  1855.   sprintf(STR1, "* Translating %s", MidiFileName.p);
  1856.   WriteDebugInfo(STR1);
  1857.   WriteDebugInfo("*                  into ");
  1858.   sprintf(STR1, "*             %s", TeXFileName.p);
  1859.   WriteDebugInfo(STR1);
  1860.   WriteDebugInfo("***********************************************");
  1861. free((char *)PS);
  1862. }  /* InitFileDebug */
  1863.  
  1864. /**********************************************/
  1865.  void Initialize(P_argc,P_argv)
  1866.  int P_argc;
  1867.  char *P_argv[];
  1868. {
  1869.   /**********************************************/
  1870.   _TP_debug_init();
  1871.   _TP_Decl_init();
  1872.   _TP_Misc_init();
  1873.   _TP_Heap1_init();
  1874.   _TP_M2TF4_init();
  1875.   MidiFileOpened = false;
  1876.   DebugFileOpened = false;
  1877.   DebugFileOpened = false;
  1878.   /* if ((Ms = (MsArray *)malloc(sizeof(MsArray))==NULL)) ErrorExit(9L); */
  1879.   InitNotePool();
  1880.   memset((&PieceContr), 0, sizeof(ControlInfo));
  1881.   for (i = 1; i <= NoTracks; i++)
  1882.     memset((&TrackArray[i - 1]), 0, sizeof(TrackRecord));
  1883.  
  1884.   InitFilRec(&HlpFilRec);
  1885.   for (i = 1; i <= NoTracks; i++)
  1886.     InitFilRec(&TrackArray[i - 1].FilRec);
  1887.  
  1888.   for (i = 1; i <= NoTracks; i++)
  1889.     TrackOrder[i - 1] = i;
  1890.   for (i = 0; i <= MAXSLURR; i++)
  1891.     SlurrIndexes[i] = false;
  1892.   TrackArray[0].Skip = true;   /* Always  skip track 1 */
  1893.   OrderIndex = 1;
  1894.   NoOfSkips = 1;
  1895.   PieceContr.PartOverRule = false;
  1896.   Quantizing = false;
  1897.   TeXHeaderFinished = false;
  1898.   ChangedContext = FALSE;
  1899.   ninstruments = 0;
  1900.   nTracksInInstr = 0;
  1901.   ScoreWidth = 1600;   /* 0.1 mm */
  1902.   /* MusicTeX standard */
  1903.   ScoreHeight = 2400;   /* 0.1 mm */
  1904.   LineHeight = 160;   /* 0.1 mm */
  1905.   ElemSkip = (long)(10 * PT);    /* 3.5 mm */
  1906.   /* STandard \elemskip */
  1907.   CumLength = 220;   /* initialize cumulative length and height  */
  1908.   Indent = 115;
  1909.   BarIndent = 40;
  1910.   ScoreSep = 20;
  1911.   MeasureMaxCnt = 0;   /* Maximum number of notes in a measure     */
  1912.   MusicSize = 20;
  1913.   SizingChanged = false;
  1914.   BatchProcessing = false;
  1915.   NoOfPages = 1;
  1916.   QuantTime = 16;   /* default value */
  1917.   InitFileDebug(P_argc,P_argv);
  1918. }  /* Initialize */
  1919.  
  1920. /*****************************************************/
  1921.  Void CleanUpSlurrArrays()
  1922. {
  1923.   /*****************************************************/
  1924.   long i, j, TmpIndx, FORLIM;
  1925.   TrackRecord *WITH;
  1926. /*  Char STR1[256], STR2[256]; */
  1927.  
  1928.   TmpIndx = 0;
  1929.   FORLIM = ntracks;
  1930.   for (j = 0; j < FORLIM; j++) {
  1931.     WITH = &TrackArray[j];
  1932.     i = 1;
  1933.     while (i <= WITH->SlurrPt) {
  1934.       if (!WITH->SlurrArray[i - 1].Occupied) {   /* is processed, remove... */
  1935.     sprintf(STR1, "Removing slurr #%3ld",(long)WITH->SlurrArray[i - 1].Numb2);
  1936.     WriteDebugInfo(STR1);
  1937.     SlurrIndexes[WITH->SlurrArray[i - 1].Numb2] = false;
  1938.     if (i < MAXSLURR) {
  1939.       memmove((&WITH->SlurrArray[i - 1]),
  1940.           (&WITH->SlurrArray[i]),
  1941.           (MAXSLURR - i) * sizeof(SlurrRecord));
  1942.       i--;
  1943.       WITH->SlurrPt--;   /* dit werkt niet !!! */
  1944.     } else {
  1945.       memset((&WITH->SlurrArray[i - 1]), 0, sizeof(SlurrRecord));
  1946.       WITH->SlurrPt--;
  1947.     }
  1948.       }
  1949.       i++;
  1950.     }
  1951.     if (WITH->SlurrPt < 0)   /* for safety */
  1952.       WITH->SlurrPt = 0;
  1953.     if (WITH->SlurrPt == 0)
  1954.       WITH->Slurring = false;
  1955.   }
  1956. }
  1957.  
  1958.  
  1959.  
  1960. /************************************************************/
  1961.  Void CleanUpTracks()
  1962. {
  1963.   /************************************************************/
  1964.   NoteRecord *N, *P;
  1965.   long All, i;
  1966.   uchar curtrack;
  1967.   MeasureTime TmpTime;
  1968.   uchar FORLIM;
  1969.   TrackRecord *WITH;
  1970.   /* Char STR1[256],STR2[256], STR3[256]; */
  1971.  
  1972.   SetTim(&TmpTime, (int)(MeasureCount + 1), 0);
  1973.   FORLIM = ntracks;
  1974.   for (curtrack = 0; curtrack < FORLIM; curtrack++) {   /* with thistrack */
  1975.     WITH = &TrackArray[curtrack];
  1976.     All = WITH->NoteList.Size;
  1977.     LastNote(WITH->NoteList, &N);
  1978.     PrevNote(N, &P);
  1979.     for (i = 1; i <= All; i++) {
  1980.       switch (N->Event) {
  1981.  
  1982.       case VOID:
  1983.     Re_move(&WITH->NoteList, N);
  1984.     BringFreeNote(N);
  1985.     break;
  1986.     /* if notearry */
  1987.  
  1988.       case REST:
  1989.       case NOTEOFF:
  1990.     if (TimeDiff(TmpTime, N->EndTime) < 0) {
  1991.       sprintf(STR1, "Extending event %3d into next measure",N->NoteVal);
  1992.       WriteDebugInfo(STR1);
  1993.       SetTim(&N->StartTime, (int)(MeasureCount + 1), 0);
  1994.     } else {
  1995.       Re_move(&WITH->NoteList, N);
  1996.       BringFreeNote(N);
  1997.     }
  1998.     break;
  1999.  
  2000.       case NOTEON:
  2001.     SetTim(&N->StartTime, (int)(MeasureCount + 1), 0);
  2002.     break;
  2003.  
  2004.       case TXT:
  2005.     free(N->MetaTxt);
  2006.     Re_move(&WITH->NoteList, N);
  2007.     BringFreeNote(N);
  2008.     break;
  2009.  
  2010.       case PEDAL:
  2011.       case KEYSIGN:
  2012.       case SIGNATURE:
  2013.     if (TimeDiff(TmpTime, N->StartTime) < 0) {
  2014.       sprintf(STR1, "META event %s still on stack...????", N->MetaTxt);
  2015.       WriteDebugInfo(STR1);
  2016.     } else {
  2017.       Re_move(&WITH->NoteList, N);
  2018.       BringFreeNote(N);
  2019.     }
  2020.     break;
  2021.  
  2022.       }/* case */
  2023.       N = P;
  2024.       PrevNote(N, &P);
  2025.     }
  2026.     sprintf(STR1, "There are %3d notes which slurr to next measure",
  2027.         WITH->NoteList.Size);
  2028.     WriteDebugInfo(STR1);
  2029.     /* If NoteList.Size>0 Then WriteDebugInfo('First note now has value :'+
  2030.                                         B2S(FirstNote(NoteList)^.NoteVal));
  2031.      */
  2032.  
  2033.     /* Clean up the BeamArray and ChordArray too */
  2034.  
  2035.     ResetBeamArray(WITH->BeamArray);
  2036.     ResetChordArray(WITH->ChordArray);
  2037.     ResetAccKeys();
  2038.  
  2039.   }
  2040.   CleanUpSlurrArrays();
  2041. }
  2042.  
  2043.  
  2044. /**************************************************/
  2045.  Char *RestString(Result, ValType, Clef)
  2046. Char *Result;
  2047. NoteTypes ValType;
  2048. ClefType Clef;
  2049. {
  2050.   /**************************************************/
  2051.   Char c1, c2;
  2052.  
  2053.   switch (Clef) {
  2054.  
  2055.   case VIOLIN:
  2056.     c1 = 'g';
  2057.     c2 = 'j';
  2058.     break;
  2059.  
  2060.   case BASS:
  2061.     c1 = 'J';
  2062.     c2 = 'K';
  2063.     break;
  2064.   }
  2065.   switch (ValType) {
  2066.  
  2067.   case WH:
  2068.     strcpy(Result, "\\pause ");
  2069.     break;
  2070.  
  2071.   case WHP:
  2072.     sprintf(Result, "\\rlap{\\qsk\\pt %c}\\pause ", c2);
  2073.     break;
  2074.  
  2075.   case WHPP:
  2076.     sprintf(Result, "\\rlap{\\qsk\\ppt %c}\\pause ", c2);
  2077.     break;
  2078.  
  2079.   case H:
  2080.     strcpy(Result, "\\hpause ");
  2081.     break;
  2082.  
  2083.   case HP:
  2084.     sprintf(Result, "\\rlap{\\qsk\\pt %c}\\hpause ", c2);
  2085.     break;
  2086.  
  2087.   case HPP:
  2088.     sprintf(Result, "\\rlap{\\qsk\\ppt %c}\\hpause ", c2);
  2089.     break;
  2090.  
  2091.   case HPPP:
  2092.     strcpy(Result, "\\pause ");
  2093.     break;
  2094.  
  2095.   case Q:
  2096.     strcpy(Result, "\\soupir ");
  2097.     break;
  2098.  
  2099.   case QP:
  2100.     sprintf(Result, "\\pt %c\\soupir ", c1);
  2101.     break;
  2102.  
  2103.   case QPP:
  2104.     sprintf(Result, "\\ppt %c\\soupir ", c1);
  2105.     break;
  2106.  
  2107.   case QPPP:
  2108.     sprintf(Result, "\\pppt %c\\soupir ", c1);
  2109.     break;
  2110.  
  2111.   case C:
  2112.     strcpy(Result, "\\ds ");
  2113.     break;
  2114.  
  2115.   case CP:
  2116.     sprintf(Result, "\\pt %c\\ds ", c1);
  2117.     break;
  2118.  
  2119.   case C3:
  2120.     strcpy(Result, "\\ds ");
  2121.     break;
  2122.  
  2123.   case CPP:
  2124.     sprintf(Result, "\\ppt %c\\ds ", c1);
  2125.     break;
  2126.  
  2127.   case CPPP:
  2128.     sprintf(Result, "\\pppt %c\\ds ", c1);
  2129.     break;
  2130.  
  2131.   case CC:
  2132.     strcpy(Result, "\\qs ");
  2133.     break;
  2134.  
  2135.   case CCP:
  2136.     sprintf(Result, "\\pt %c\\qs ", c1);
  2137.     break;
  2138.  
  2139.   case CCPP:
  2140.     sprintf(Result, "\\ppt %c\\qs ", c1);
  2141.     break;
  2142.  
  2143.   case CC3:
  2144.     strcpy(Result, "\\qs ");
  2145.     break;
  2146.  
  2147.   case CCC:
  2148.     strcpy(Result, "\\qs ");
  2149.     break;
  2150.  
  2151.   case CCCP:
  2152.     strcpy(Result, " ");
  2153.     break;
  2154.  
  2155.   case CCC3:
  2156.     strcpy(Result, " ");
  2157.     break;
  2158.  
  2159.   case CCCC:
  2160.     strcpy(Result, " ");
  2161.     break;
  2162.  
  2163.   case CCCCP:
  2164.     strcpy(Result, " ");
  2165.     break;
  2166.  
  2167.   case CCCC3:
  2168.     strcpy(Result, " ");
  2169.     break;
  2170.   }/* case */
  2171.   return Result;
  2172. }  /* RestString */
  2173.  
  2174.  
  2175. /**************************************/
  2176. uchar Index(uchar value)
  2177. {
  2178.   /**************************************/
  2179.   uchar Result, Modulo, TmpIndx;
  2180.   long Okt;
  2181.  
  2182.   if (value > 127) {
  2183.     Warning("Found a notevalue exceeding 127, replacing with 60 !");
  2184.     value = 60;
  2185.   }
  2186.   Okt = value - 60;
  2187.   Okt /= 12;
  2188.   /* WriteDebugInfo('Index->Okt='+I2S(Okt)); */
  2189.   Modulo = value % 12;
  2190.   /* WriteDebugInfo('Index->Modulo='+I2S(Modulo)); */
  2191.   TmpIndx = CPosition + Okt * 7;
  2192.   /* WriteDebugInfo('Index->TmpIndx='+I2S(TmpIndx)); */
  2193.   if (value > 60) {
  2194.     switch (Modulo) {
  2195.  
  2196.     case 0:
  2197.       Result = TmpIndx;
  2198.       break;
  2199.  
  2200.     case 2:
  2201.       Result = TmpIndx + 1;
  2202.       break;
  2203.  
  2204.     case 4:
  2205.       Result = TmpIndx + 2;
  2206.       break;
  2207.  
  2208.     case 5:
  2209.       Result = TmpIndx + 3;
  2210.       break;
  2211.  
  2212.     case 7:
  2213.       Result = TmpIndx + 4;
  2214.       break;
  2215.  
  2216.     case 9:
  2217.       Result = TmpIndx + 5;
  2218.       break;
  2219.  
  2220.     case 11:
  2221.       Result = TmpIndx + 6;
  2222.       break;
  2223.  
  2224.     default:
  2225.       Result = TmpIndx;
  2226.       break;
  2227.     }
  2228.     return Result;
  2229.   }
  2230.   switch (Modulo) {
  2231.  
  2232.   case 2:
  2233.     Result = TmpIndx - 6;
  2234.     break;
  2235.  
  2236.   case 4:
  2237.     Result = TmpIndx - 5;
  2238.     break;
  2239.  
  2240.   case 5:
  2241.     Result = TmpIndx - 4;
  2242.     break;
  2243.  
  2244.   case 7:
  2245.     Result = TmpIndx - 3;
  2246.     break;
  2247.  
  2248.   case 9:
  2249.     Result = TmpIndx - 2;
  2250.     break;
  2251.  
  2252.   case 11:
  2253.     Result = TmpIndx - 1;
  2254.     break;
  2255.  
  2256.   default:
  2257.     Result = TmpIndx;
  2258.     break;
  2259.   }
  2260.  
  2261.   return Result;
  2262. }  /* Index */
  2263.  
  2264.  
  2265.  
  2266. /************************************************************************/
  2267. Char *ValueString(char *Result,uchar value,ControlInfo Control,AccKeyType *AKey,boolean ChangeAKey)
  2268. /* Char *Result;
  2269. uchar value;
  2270. ControlInfo Control;
  2271. AccKeyType *AKey;
  2272. boolean ChangeAKey;*/
  2273. {
  2274.   /************************************************************************/
  2275.   unsigned int Modulo;
  2276.  
  2277.   Modulo = value % 12;
  2278.  
  2279.   /* The Accidental records should be in connection with each track, not with  */
  2280.   /* the control structure. In that case this function should include the      */
  2281.   /* track as a parameter.                                                     */
  2282.  
  2283.   switch (Modulo) {
  2284.  
  2285.   case 0:
  2286.     switch (Control.KeySign) {
  2287.  
  2288.     case -7:
  2289.     case -6:
  2290.       if (AKey->c == NON) {
  2291.     sprintf(Result, "{=%s}", Notes[Index(value) - 1]);
  2292.     if (ChangeAKey)
  2293.       AKey->c = CORRECT;
  2294.       } else
  2295.     sprintf(Result, "%s", Notes[Index(value) - 1]);
  2296.       break;
  2297.  
  2298.     case 2:
  2299.     case 3:
  2300.     case 4:
  2301.     case 5:
  2302.     case 6:
  2303.     case 7:
  2304.     case 8:
  2305.       if (AKey->c == NON) {
  2306.     sprintf(Result, "{=%s}", Notes[Index(value) - 1]);
  2307.     if (ChangeAKey)
  2308.       AKey->c = CORRECT;
  2309.       } else
  2310.     sprintf(Result, "%s", Notes[Index(value) - 1]);
  2311.       break;
  2312.  
  2313.     default:
  2314.       if (AKey->c != NON) {
  2315.     sprintf(Result, "{=%s}", Notes[Index(value) - 1]);
  2316.     if (ChangeAKey)
  2317.       AKey->c = NON;
  2318.       } else
  2319.     sprintf(Result, "%s", Notes[Index(value) - 1]);
  2320.       break;
  2321.     }/* case */
  2322.     break;
  2323.  
  2324.   case 1:
  2325.     switch (Control.KeySign) {
  2326.  
  2327.     case 2:
  2328.     case 3:
  2329.     case 4:
  2330.     case 5:
  2331.     case 6:
  2332.     case 7:
  2333.     case 8:
  2334.       if (AKey->c == CORRECT) {
  2335.     sprintf(Result, "{^%s}", Notes[Index(value - 1) - 1]);
  2336.     if (ChangeAKey)
  2337.       AKey->c = NON;
  2338.       } else
  2339.     sprintf(Result, "%s", Notes[Index(value - 1) - 1]);
  2340.       break;
  2341.  
  2342.     case -8:
  2343.     case -7:
  2344.     case -6:
  2345.     case -5:
  2346.     case -4:
  2347.       if (AKey->d == CORRECT) {
  2348.     sprintf(Result, "{_%s}", Notes[Index(value + 1) - 1]);
  2349.     if (ChangeAKey)
  2350.       AKey->d = NON;
  2351.       } else
  2352.     sprintf(Result, "%s", Notes[Index(value + 1) - 1]);
  2353.       break;
  2354.  
  2355.     default:
  2356.       if (AKey->c == SHARP)
  2357.     sprintf(Result, "%s", Notes[Index(value - 1) - 1]);
  2358.       else if (AKey->d == FLAT)
  2359.     sprintf(Result, "%s", Notes[Index(value + 1) - 1]);
  2360.       else {
  2361.     switch (Control.KeySign) {
  2362.  
  2363.     case -8:
  2364.     case -7:
  2365.     case -6:
  2366.     case -5:
  2367.     case -4:
  2368.     case -3:
  2369.     case -2:
  2370.     case -1:
  2371.       sprintf(Result, "{_%s}", Notes[Index(value + 1) - 1]);
  2372.       if (ChangeAKey)
  2373.         AKey->d = FLAT;
  2374.       break;
  2375.  
  2376.     case 0:
  2377.     case 1:
  2378.     case 2:
  2379.     case 3:
  2380.     case 4:
  2381.     case 5:
  2382.     case 6:
  2383.     case 7:
  2384.     case 8:
  2385.       sprintf(Result, "{^%s}", Notes[Index(value - 1) - 1]);
  2386.       if (ChangeAKey)
  2387.         AKey->c = SHARP;
  2388.       break;
  2389.     }
  2390.       }
  2391.       break;
  2392.     }/* Case KeySign */
  2393.     break;
  2394.  
  2395.   case 2:
  2396.     switch (Control.KeySign) {
  2397.  
  2398.     case -8:
  2399.     case -7:
  2400.     case -6:
  2401.     case -5:
  2402.     case -4:
  2403.       if (AKey->d == NON) {
  2404.     sprintf(Result, "{=%s}", Notes[Index(value) - 1]);
  2405.     if (ChangeAKey)
  2406.       AKey->d = CORRECT;
  2407.       } else
  2408.     sprintf(Result, "%s", Notes[Index(value) - 1]);
  2409.       break;
  2410.  
  2411.     case 4:
  2412.     case 5:
  2413.     case 6:
  2414.     case 7:
  2415.     case 8:
  2416.       if (AKey->d == NON) {
  2417.     sprintf(Result, "{=%s}", Notes[Index(value) - 1]);
  2418.     if (ChangeAKey)
  2419.       AKey->d = CORRECT;
  2420.       } else
  2421.     sprintf(Result, "%s", Notes[Index(value) - 1]);
  2422.       break;
  2423.  
  2424.     default:
  2425.       if (AKey->d != NON) {
  2426.     sprintf(Result, "{=%s}", Notes[Index(value) - 1]);
  2427.     if (ChangeAKey)
  2428.       AKey->d = NON;
  2429.       } else
  2430.     sprintf(Result, "%s", Notes[Index(value) - 1]);
  2431.       break;
  2432.     }/* case */
  2433.     break;
  2434.  
  2435.   case 3:
  2436.     switch (Control.KeySign) {
  2437.  
  2438.     case 4:
  2439.     case 5:
  2440.     case 6:
  2441.     case 7:
  2442.     case 8:
  2443.       if (AKey->d == CORRECT) {
  2444.     sprintf(Result, "{^%s}", Notes[Index(value - 1) - 1]);
  2445.     if (ChangeAKey)
  2446.       AKey->d = NON;
  2447.       } else
  2448.     sprintf(Result, "%s", Notes[Index(value - 1) - 1]);
  2449.       break;
  2450.  
  2451.     case -8:
  2452.     case -7:
  2453.     case -6:
  2454.     case -5:
  2455.     case -4:
  2456.     case -3:
  2457.     case -2:
  2458.       if (AKey->e == CORRECT) {
  2459.     sprintf(Result, "{_%s}", Notes[Index(value + 1) - 1]);
  2460.     if (ChangeAKey)
  2461.       AKey->e = NON;
  2462.       } else
  2463.     sprintf(Result, "%s", Notes[Index(value + 1) - 1]);
  2464.       break;
  2465.  
  2466.     default:
  2467.       if (AKey->d == SHARP)
  2468.     sprintf(Result, "%s", Notes[Index(value - 1) - 1]);
  2469.       else if (AKey->e == FLAT)
  2470.     sprintf(Result, "%s", Notes[Index(value + 1) - 1]);
  2471.       else {
  2472.     switch (Control.KeySign) {
  2473.  
  2474.     case -8:
  2475.     case -7:
  2476.     case -6:
  2477.     case -5:
  2478.     case -4:
  2479.     case -3:
  2480.     case -2:
  2481.     case -1:
  2482.       sprintf(Result, "{_%s}", Notes[Index(value + 1) - 1]);
  2483.       if (ChangeAKey)
  2484.         AKey->e = FLAT;
  2485.       break;
  2486.  
  2487.     case 0:
  2488.     case 1:
  2489.     case 2:
  2490.     case 3:
  2491.     case 4:
  2492.     case 5:
  2493.     case 6:
  2494.     case 7:
  2495.     case 8:
  2496.       sprintf(Result, "{^%s}", Notes[Index(value - 1) - 1]);
  2497.       if (ChangeAKey)
  2498.         AKey->d = SHARP;
  2499.       break;
  2500.     }
  2501.       }
  2502.       break;
  2503.     }/* Case KeySign */
  2504.     break;
  2505.  
  2506.   case 4:
  2507.     switch (Control.KeySign) {
  2508.  
  2509.     case -7:
  2510.     case -6:
  2511.     case -5:
  2512.     case -4:
  2513.     case -3:
  2514.     case -2:
  2515.       if (AKey->e == NON) {
  2516.     sprintf(Result, "{=%s}", Notes[Index(value) - 1]);
  2517.     if (ChangeAKey)
  2518.       AKey->e = CORRECT;
  2519.       } else
  2520.     sprintf(Result, "%s", Notes[Index(value) - 1]);
  2521.       break;
  2522.  
  2523.     case 6:
  2524.     case 7:
  2525.     case 8:
  2526.       if (AKey->e == NON) {
  2527.     sprintf(Result, "{=%s}", Notes[Index(value) - 1]);
  2528.     if (ChangeAKey)
  2529.       AKey->e = CORRECT;
  2530.       } else
  2531.     sprintf(Result, "%s", Notes[Index(value) - 1]);
  2532.       break;
  2533.  
  2534.     default:
  2535.       if (AKey->e != NON) {
  2536.     sprintf(Result, "{=%s}", Notes[Index(value) - 1]);
  2537.     if (ChangeAKey)
  2538.       AKey->e = NON;
  2539.       } else
  2540.     sprintf(Result, "%s", Notes[Index(value) - 1]);
  2541.       break;
  2542.     }/* case */
  2543.     break;
  2544.  
  2545.   case 5:
  2546.     switch (Control.KeySign) {
  2547.  
  2548.     case -7:
  2549.       if (AKey->f == NON) {
  2550.     sprintf(Result, "{=%s}", Notes[Index(value) - 1]);
  2551.     if (ChangeAKey)
  2552.       AKey->f = CORRECT;
  2553.       } else
  2554.     sprintf(Result, "%s", Notes[Index(value) - 1]);
  2555.       break;
  2556.  
  2557.     case 1:
  2558.     case 2:
  2559.     case 3:
  2560.     case 4:
  2561.     case 5:
  2562.     case 6:
  2563.     case 7:
  2564.     case 8:
  2565.       if (AKey->f == NON) {
  2566.     sprintf(Result, "{=%s}", Notes[Index(value) - 1]);
  2567.     if (ChangeAKey)
  2568.       AKey->f = CORRECT;
  2569.       } else
  2570.     sprintf(Result, "%s", Notes[Index(value) - 1]);
  2571.       break;
  2572.  
  2573.     default:
  2574.       if (AKey->f != NON) {
  2575.     sprintf(Result, "{=%s}", Notes[Index(value) - 1]);
  2576.     if (ChangeAKey)
  2577.       AKey->f = NON;
  2578.       } else
  2579.     sprintf(Result, "%s", Notes[Index(value) - 1]);
  2580.       break;
  2581.     }/* case */
  2582.     break;
  2583.  
  2584.   case 6:
  2585.     switch (Control.KeySign) {
  2586.  
  2587.     case 1:
  2588.     case 2:
  2589.     case 3:
  2590.     case 4:
  2591.     case 5:
  2592.     case 6:
  2593.     case 7:
  2594.     case 8:
  2595.       if (AKey->f == CORRECT) {
  2596.     sprintf(Result, "{^%s}", Notes[Index(value - 1) - 1]);
  2597.     if (ChangeAKey)
  2598.       AKey->f = NON;
  2599.       } else
  2600.     sprintf(Result, "%s", Notes[Index(value - 1) - 1]);
  2601.       break;
  2602.  
  2603.     case -8:
  2604.     case -7:
  2605.     case -6:
  2606.     case -5:
  2607.       if (AKey->g == CORRECT) {
  2608.     sprintf(Result, "{_%s}", Notes[Index(value + 1) - 1]);
  2609.     if (ChangeAKey)
  2610.       AKey->g = NON;
  2611.       } else
  2612.     sprintf(Result, "%s", Notes[Index(value + 1) - 1]);
  2613.       break;
  2614.  
  2615.     default:
  2616.       if (AKey->f == SHARP)
  2617.     sprintf(Result, "%s", Notes[Index(value - 1) - 1]);
  2618.       else if (AKey->g == FLAT)
  2619.     sprintf(Result, "%s", Notes[Index(value + 1) - 1]);
  2620.       else {
  2621.     switch (Control.KeySign) {
  2622.  
  2623.     case -8:
  2624.     case -7:
  2625.     case -6:
  2626.     case -5:
  2627.     case -4:
  2628.     case -3:
  2629.     case -2:
  2630.     case -1:
  2631.       sprintf(Result, "{_%s}", Notes[Index(value + 1) - 1]);
  2632.       if (ChangeAKey)
  2633.         AKey->g = FLAT;
  2634.       break;
  2635.  
  2636.     case 0:
  2637.     case 1:
  2638.     case 2:
  2639.     case 3:
  2640.     case 4:
  2641.     case 5:
  2642.     case 6:
  2643.     case 7:
  2644.     case 8:
  2645.       sprintf(Result, "{^%s}", Notes[Index(value - 1) - 1]);
  2646.       if (ChangeAKey)
  2647.         AKey->f = SHARP;
  2648.       break;
  2649.     }
  2650.       }
  2651.       break;
  2652.     }/* Case KeySign */
  2653.     break;
  2654.  
  2655.   case 7:
  2656.     switch (Control.KeySign) {
  2657.  
  2658.     case -7:
  2659.     case -6:
  2660.     case -5:
  2661.       if (AKey->g == NON) {
  2662.     sprintf(Result, "{=%s}", Notes[Index(value) - 1]);
  2663.     if (ChangeAKey)
  2664.       AKey->g = CORRECT;
  2665.       } else
  2666.     sprintf(Result, "%s", Notes[Index(value) - 1]);
  2667.       break;
  2668.  
  2669.     case 3:
  2670.     case 4:
  2671.     case 5:
  2672.     case 6:
  2673.     case 7:
  2674.     case 8:
  2675.       if (AKey->g == NON) {
  2676.     sprintf(Result, "{=%s}", Notes[Index(value) - 1]);
  2677.     if (ChangeAKey)
  2678.       AKey->g = CORRECT;
  2679.       } else
  2680.     sprintf(Result, "%s", Notes[Index(value) - 1]);
  2681.       break;
  2682.  
  2683.     default:
  2684.       if (AKey->g != NON) {
  2685.     sprintf(Result, "{=%s}", Notes[Index(value) - 1]);
  2686.     if (ChangeAKey)
  2687.       AKey->g = NON;
  2688.       } else
  2689.     sprintf(Result, "%s", Notes[Index(value) - 1]);
  2690.       break;
  2691.     }/* case */
  2692.     break;
  2693.  
  2694.   case 8:
  2695.     switch (Control.KeySign) {
  2696.  
  2697.     case 3:
  2698.     case 4:
  2699.     case 5:
  2700.     case 6:
  2701.     case 7:
  2702.     case 8:
  2703.       if (AKey->g == CORRECT) {
  2704.     sprintf(Result, "{^%s}", Notes[Index(value - 1) - 1]);
  2705.     if (ChangeAKey)
  2706.       AKey->g = NON;
  2707.       } else
  2708.     sprintf(Result, "%s", Notes[Index(value - 1) - 1]);
  2709.       break;
  2710.  
  2711.     case -8:
  2712.     case -7:
  2713.     case -6:
  2714.     case -5:
  2715.     case -4:
  2716.     case -3:
  2717.       if (AKey->a == CORRECT) {
  2718.     sprintf(Result, "{_%s}", Notes[Index(value + 1) - 1]);
  2719.     if (ChangeAKey)
  2720.       AKey->a = NON;
  2721.       } else
  2722.     sprintf(Result, "%s", Notes[Index(value + 1) - 1]);
  2723.       break;
  2724.  
  2725.     default:
  2726.       if (AKey->g == SHARP)
  2727.     sprintf(Result, "%s", Notes[Index(value - 1) - 1]);
  2728.       else if (AKey->a == FLAT)
  2729.     sprintf(Result, "%s", Notes[Index(value + 1) - 1]);
  2730.       else {
  2731.     switch (Control.KeySign) {
  2732.  
  2733.     case -8:
  2734.     case -7:
  2735.     case -6:
  2736.     case -5:
  2737.     case -4:
  2738.     case -3:
  2739.     case -2:
  2740.     case -1:
  2741.     case 0:
  2742.       sprintf(Result, "{_%s}", Notes[Index(value + 1) - 1]);
  2743.       if (ChangeAKey)
  2744.         AKey->a = FLAT;
  2745.       break;
  2746.  
  2747.     case 1:
  2748.     case 2:
  2749.     case 3:
  2750.     case 4:
  2751.     case 5:
  2752.     case 6:
  2753.     case 7:
  2754.     case 8:
  2755.       sprintf(Result, "{^%s}", Notes[Index(value - 1) - 1]);
  2756.       if (ChangeAKey)
  2757.         AKey->g = SHARP;
  2758.       break;
  2759.     }
  2760.       }
  2761.       break;
  2762.     }/* Case KeySign */
  2763.     break;
  2764.  
  2765.   case 9:
  2766.     switch (Control.KeySign) {
  2767.  
  2768.     case -7:
  2769.     case -6:
  2770.     case -5:
  2771.     case -4:
  2772.     case -3:
  2773.       if (AKey->a == NON) {
  2774.     sprintf(Result, "{=%s}", Notes[Index(value) - 1]);
  2775.     if (ChangeAKey)
  2776.       AKey->a = CORRECT;
  2777.       } else
  2778.     sprintf(Result, "%s", Notes[Index(value) - 1]);
  2779.       break;
  2780.  
  2781.     case 5:
  2782.     case 6:
  2783.     case 7:
  2784.     case 8:
  2785.       if (AKey->a == NON) {
  2786.     sprintf(Result, "{=%s}", Notes[Index(value) - 1]);
  2787.     if (ChangeAKey)
  2788.       AKey->a = CORRECT;
  2789.       } else
  2790.     sprintf(Result, "%s", Notes[Index(value) - 1]);
  2791.       break;
  2792.  
  2793.     default:
  2794.       if (AKey->a != NON) {
  2795.     sprintf(Result, "{=%s}", Notes[Index(value) - 1]);
  2796.     if (ChangeAKey)
  2797.       AKey->a = NON;
  2798.       } else
  2799.     sprintf(Result, "%s", Notes[Index(value) - 1]);
  2800.       break;
  2801.     }/* case */
  2802.     break;
  2803.  
  2804.   case 10:
  2805.     switch (Control.KeySign) {
  2806.  
  2807.     case 5:
  2808.     case 6:
  2809.     case 7:
  2810.     case 8:
  2811.       if (AKey->a == CORRECT) {
  2812.     sprintf(Result, "{^%s}", Notes[Index(value - 1) - 1]);
  2813.     if (ChangeAKey)
  2814.       AKey->a = NON;
  2815.       } else
  2816.     sprintf(Result, "%s", Notes[Index(value - 1) - 1]);
  2817.       break;
  2818.  
  2819.     case -8:
  2820.     case -7:
  2821.     case -6:
  2822.     case -5:
  2823.     case -4:
  2824.     case -3:
  2825.     case -2:
  2826.     case -1:
  2827.       if (AKey->b == CORRECT) {
  2828.     sprintf(Result, "{_%s}", Notes[Index(value + 1) - 1]);
  2829.     if (ChangeAKey)
  2830.       AKey->b = NON;
  2831.       } else
  2832.     sprintf(Result, "%s", Notes[Index(value + 1) - 1]);
  2833.       break;
  2834.  
  2835.     default:
  2836.       if (AKey->a == SHARP)
  2837.     sprintf(Result, "%s", Notes[Index(value - 1) - 1]);
  2838.       else if (AKey->b == FLAT)
  2839.     sprintf(Result, "%s", Notes[Index(value + 1) - 1]);
  2840.       else {
  2841.     switch (Control.KeySign) {
  2842.  
  2843.     case -8:
  2844.     case -7:
  2845.     case -6:
  2846.     case -5:
  2847.     case -4:
  2848.     case -3:
  2849.     case -2:
  2850.     case -1:
  2851.     case 0:
  2852.       sprintf(Result, "{_%s}", Notes[Index(value + 1) - 1]);
  2853.       if (ChangeAKey)
  2854.         AKey->b = FLAT;
  2855.       break;
  2856.  
  2857.     case 1:
  2858.     case 2:
  2859.     case 3:
  2860.     case 4:
  2861.     case 5:
  2862.     case 6:
  2863.     case 7:
  2864.     case 8:
  2865.       sprintf(Result, "{^%s}", Notes[Index(value - 1) - 1]);
  2866.       if (ChangeAKey)
  2867.         AKey->a = SHARP;
  2868.       break;
  2869.     }
  2870.       }
  2871.       break;
  2872.     }/* Case KeySign */
  2873.     break;
  2874.  
  2875.   case 11:
  2876.     switch (Control.KeySign) {
  2877.  
  2878.     case -8:
  2879.     case -7:
  2880.     case -6:
  2881.     case -5:
  2882.     case -4:
  2883.     case -3:
  2884.     case -2:
  2885.     case -1:
  2886.       if (AKey->b == NON) {
  2887.     sprintf(Result, "{=%s}", Notes[Index(value) - 1]);
  2888.     if (ChangeAKey)
  2889.       AKey->b = CORRECT;
  2890.       } else
  2891.     sprintf(Result, "%s", Notes[Index(value) - 1]);
  2892.       break;
  2893.  
  2894.     case 8:
  2895.       if (AKey->b == NON) {
  2896.     sprintf(Result, "{=%s}", Notes[Index(value) - 1]);
  2897.     if (ChangeAKey)
  2898.       AKey->b = CORRECT;
  2899.       } else
  2900.     sprintf(Result, "%s", Notes[Index(value) - 1]);
  2901.       break;
  2902.  
  2903.     default:
  2904.       if (AKey->b != NON) {
  2905.     sprintf(Result, "{=%s}", Notes[Index(value) - 1]);
  2906.     if (ChangeAKey)
  2907.       AKey->b = NON;
  2908.       } else
  2909.     sprintf(Result, "%s", Notes[Index(value) - 1]);
  2910.       break;
  2911.     }/* case */
  2912.     break;
  2913.  
  2914.   }
  2915.  
  2916.  
  2917.   return Result;
  2918. }  /* ValueSTring */
  2919.  
  2920. /*  variables for Note2String: 
  2921. struct LOC_Note2String {
  2922.   NoteRecord ThisNote;
  2923. } ;*/
  2924.  
  2925. /*------------------------------*/
  2926.  Char HangOrBang(LINK)
  2927. struct LOC_Note2String *LINK;
  2928. {
  2929.   /*------------------------------*/
  2930.   if (LINK->ThisNote.Orient == UP)
  2931.     return 'u';
  2932.   else
  2933.     return 'l';
  2934. }
  2935.  
  2936.  
  2937. /**************************************************************************/
  2938.  Char *Note2String(Result, ThisNote_, Clef, AKey)
  2939. Char *Result;
  2940. NoteRecord ThisNote_;
  2941. ClefType Clef;
  2942. AccKeyType *AKey;
  2943. {
  2944.   /***************************************************************************/
  2945.   struct LOC_Note2String V;
  2946.   Char STR1[20]; /* STR2[256]; */
  2947.  
  2948.   V.ThisNote = ThisNote_;
  2949.   switch (V.ThisNote.Event) {
  2950.  
  2951.   case NOTEON:
  2952.   case NOTEOFF:
  2953.     switch (V.ThisNote.NoteType) {
  2954.  
  2955.     case WH:
  2956.       sprintf(Result, "\\wh %s",
  2957.           ValueString(STR1, V.ThisNote.NoteVal, PieceContr, AKey, true));
  2958.       break;
  2959.  
  2960.     case WHP:
  2961.       sprintf(Result, "\\whp %s",
  2962.           ValueString(STR1, V.ThisNote.NoteVal, PieceContr, AKey, true));
  2963.       break;
  2964.  
  2965.     case WHPP:
  2966.       sprintf(Result, "\\whpp %s",
  2967.           ValueString(STR1, V.ThisNote.NoteVal, PieceContr, AKey, true));
  2968.       break;
  2969.  
  2970.     case WHPPP:
  2971.       sprintf(Result, "\\whppp %s",
  2972.           ValueString(STR1, V.ThisNote.NoteVal, PieceContr, AKey, true));
  2973.       break;
  2974.  
  2975.     case H:
  2976.       sprintf(Result, "\\h%c %s",
  2977.           HangOrBang(&V),
  2978.           ValueString(STR1, V.ThisNote.NoteVal, PieceContr, AKey, true));
  2979.       break;
  2980.  
  2981.     case HP:
  2982.       sprintf(Result, "\\h%cp %s",
  2983.           HangOrBang(&V),
  2984.           ValueString(STR1, V.ThisNote.NoteVal, PieceContr, AKey, true));
  2985.       break;
  2986.  
  2987.     case HPP:
  2988.       sprintf(Result, "\\h%cpp %s",
  2989.           HangOrBang(&V),
  2990.           ValueString(STR1, V.ThisNote.NoteVal, PieceContr, AKey, true));
  2991.       break;
  2992.  
  2993.     case HPPP:
  2994.       sprintf(Result, "\\h%cppp %s",
  2995.           HangOrBang(&V),
  2996.           ValueString(STR1, V.ThisNote.NoteVal, PieceContr, AKey, true));
  2997.       break;
  2998.  
  2999.     case Q:
  3000.       sprintf(Result, "\\q%c %s",
  3001.           HangOrBang(&V),
  3002.           ValueString(STR1, V.ThisNote.NoteVal, PieceContr, AKey, true));
  3003.       break;
  3004.  
  3005.     case QP:
  3006.       sprintf(Result, "\\q%cp %s",
  3007.           HangOrBang(&V),
  3008.           ValueString(STR1, V.ThisNote.NoteVal, PieceContr, AKey, true));
  3009.       break;
  3010.  
  3011.     case QPP:
  3012.       sprintf(Result, "\\q%cpp %s",
  3013.           HangOrBang(&V),
  3014.           ValueString(STR1, V.ThisNote.NoteVal, PieceContr, AKey, true));
  3015.       break;
  3016.  
  3017.     case QPPP:
  3018.       sprintf(Result, "\\q%cppp %s",
  3019.           HangOrBang(&V),
  3020.           ValueString(STR1, V.ThisNote.NoteVal, PieceContr, AKey, true));
  3021.       break;
  3022.  
  3023.     case C:
  3024.       sprintf(Result, "\\c%c %s",
  3025.           HangOrBang(&V),
  3026.           ValueString(STR1, V.ThisNote.NoteVal, PieceContr, AKey, true));
  3027.       break;
  3028.  
  3029.     case CP:
  3030.       sprintf(Result, "\\c%cp %s",
  3031.           HangOrBang(&V),
  3032.           ValueString(STR1, V.ThisNote.NoteVal, PieceContr, AKey, true));
  3033.       break;
  3034.  
  3035.     case C3:
  3036.       sprintf(Result, "\\c%c %s",
  3037.           HangOrBang(&V),
  3038.           ValueString(STR1, V.ThisNote.NoteVal, PieceContr, AKey, true));
  3039.       break;
  3040.  
  3041.     case CPP:
  3042.       sprintf(Result, "\\c%cpp %s",
  3043.           HangOrBang(&V),
  3044.           ValueString(STR1, V.ThisNote.NoteVal, PieceContr, AKey, true));
  3045.       break;
  3046.  
  3047.     case CPPP:
  3048.       sprintf(Result, "\\c%cppp %s",
  3049.           HangOrBang(&V),
  3050.           ValueString(STR1, V.ThisNote.NoteVal, PieceContr, AKey, true));
  3051.       break;
  3052.  
  3053.     case CC:
  3054.       sprintf(Result, "\\cc%c %s",
  3055.           HangOrBang(&V),
  3056.           ValueString(STR1, V.ThisNote.NoteVal, PieceContr, AKey, true));
  3057.       break;
  3058.  
  3059.     case CCP:
  3060.       sprintf(Result, "\\pt %s\\cc%c %s",
  3061.           ValueString(STR1, V.ThisNote.NoteVal, PieceContr, AKey, false),
  3062.           HangOrBang(&V),
  3063.           ValueString(STR2, V.ThisNote.NoteVal, PieceContr, AKey, true));
  3064.       break;
  3065.  
  3066.     case CC3:
  3067.       sprintf(Result, "\\cc%c %s",
  3068.           HangOrBang(&V),
  3069.           ValueString(STR1, V.ThisNote.NoteVal, PieceContr, AKey, true));
  3070.       break;
  3071.  
  3072.     case CCC:
  3073.       sprintf(Result, "\\ccc%c %s",
  3074.           HangOrBang(&V),
  3075.           ValueString(STR1, V.ThisNote.NoteVal, PieceContr, AKey, true));
  3076.       break;
  3077.  
  3078.     case CCCP:
  3079.       sprintf(Result, "\\pt %s\\ccc%c %s",
  3080.           ValueString(STR1, V.ThisNote.NoteVal, PieceContr, AKey, false),
  3081.           HangOrBang(&V),
  3082.           ValueString(STR2, V.ThisNote.NoteVal, PieceContr, AKey, true));
  3083.       break;
  3084.  
  3085.     case CCC3:
  3086.       sprintf(Result, "\\ccc%c %s",
  3087.           HangOrBang(&V),
  3088.           ValueString(STR1, V.ThisNote.NoteVal, PieceContr, AKey, true));
  3089.       break;
  3090.  
  3091.     case CCCC:
  3092.       sprintf(Result, "\\cccc%c %s",
  3093.           HangOrBang(&V),
  3094.           ValueString(STR1, V.ThisNote.NoteVal, PieceContr, AKey, true));
  3095.       break;
  3096.  
  3097.     case CCCCP:
  3098.       sprintf(Result, "\\pt %s\\cccc%c %s",
  3099.           ValueString(STR1, V.ThisNote.NoteVal, PieceContr, AKey, false),
  3100.           HangOrBang(&V),
  3101.           ValueString(STR2, V.ThisNote.NoteVal, PieceContr, AKey, true));
  3102.       break;
  3103.  
  3104.     case CCCC3:
  3105.       sprintf(Result, "\\cccc%c %s",
  3106.           HangOrBang(&V),
  3107.           ValueString(STR1, V.ThisNote.NoteVal, PieceContr, AKey, true));
  3108.       break;
  3109.     }/* case */
  3110.     break;
  3111.  
  3112.   case VOID:
  3113.     strcpy(Result, "");
  3114.     break;
  3115.  
  3116.   case TXT:
  3117.     sprintf(Result, "\\uptext{%s} ", V.ThisNote.MetaTxt);
  3118.     break;
  3119.  
  3120.   case REST:
  3121.     RestString(Result, V.ThisNote.NoteType, Clef);
  3122.     break;
  3123.  
  3124.   case PEDAL:
  3125.     if (V.ThisNote.Velocity > 0)
  3126.       strcpy(Result, "\\PED");
  3127.     else
  3128.       strcpy(Result, "\\DEP");
  3129.     break;
  3130.   }/* case */
  3131.   return Result;
  3132. }  /* Note2String */
  3133.  
  3134.  
  3135.  
  3136. /**************************************************************/
  3137.  Char *ChordNote2String(Result, ThisNote, Clef, AKey)
  3138. Char *Result;
  3139. NoteRecord ThisNote;
  3140. ClefType Clef;
  3141. AccKeyType *AKey;
  3142. {
  3143.   /**************************************************************/
  3144.   Char STR1[20];
  3145.  
  3146.   switch (ThisNote.Event) {
  3147.  
  3148.   case NOTEON:
  3149.   case NOTEOFF:
  3150.     switch (ThisNote.NoteType) {
  3151.  
  3152.     case WH:
  3153.       sprintf(Result, "\\zw %s",
  3154.           ValueString(STR1, ThisNote.NoteVal, PieceContr, AKey, true));
  3155.       break;
  3156.  
  3157.     case H:
  3158.       sprintf(Result, "\\zh %s",
  3159.           ValueString(STR1, ThisNote.NoteVal, PieceContr, AKey, true));
  3160.       break;
  3161.  
  3162.     case HP:
  3163.       sprintf(Result, "\\zhp %s",
  3164.           ValueString(STR1, ThisNote.NoteVal, PieceContr, AKey, true));
  3165.       break;
  3166.  
  3167.     case HPP:
  3168.       sprintf(Result, "\\zhpp %s",
  3169.           ValueString(STR1, ThisNote.NoteVal, PieceContr, AKey, true));
  3170.       break;
  3171.  
  3172.     case HPPP:
  3173.       sprintf(Result, "\\zhppp %s",
  3174.           ValueString(STR1, ThisNote.NoteVal, PieceContr, AKey, true));
  3175.       break;
  3176.  
  3177.     case Q:
  3178.       sprintf(Result, "\\zq %s",
  3179.           ValueString(STR1, ThisNote.NoteVal, PieceContr, AKey, true));
  3180.       break;
  3181.  
  3182.     case QP:
  3183.       sprintf(Result, "\\zqp %s",
  3184.           ValueString(STR1, ThisNote.NoteVal, PieceContr, AKey, true));
  3185.       break;
  3186.  
  3187.     case QPP:
  3188.       sprintf(Result, "\\zqpp %s",
  3189.           ValueString(STR1, ThisNote.NoteVal, PieceContr, AKey, true));
  3190.       break;
  3191.  
  3192.     case QPPP:
  3193.       sprintf(Result, "\\zqppp %s",
  3194.           ValueString(STR1, ThisNote.NoteVal, PieceContr, AKey, true));
  3195.       break;
  3196.  
  3197.     case C:
  3198.       sprintf(Result, "\\zq %s",
  3199.           ValueString(STR1, ThisNote.NoteVal, PieceContr, AKey, true));
  3200.       break;
  3201.  
  3202.     case CP:
  3203.       sprintf(Result, "\\zq %s",
  3204.           ValueString(STR1, ThisNote.NoteVal, PieceContr, AKey, true));
  3205.       break;
  3206.  
  3207.     case C3:
  3208.       sprintf(Result, "\\zq %s",
  3209.           ValueString(STR1, ThisNote.NoteVal, PieceContr, AKey, true));
  3210.       break;
  3211.  
  3212.     case CPP:
  3213.       sprintf(Result, "\\zqpp %s",
  3214.           ValueString(STR1, ThisNote.NoteVal, PieceContr, AKey, true));
  3215.       break;
  3216.  
  3217.     case CPPP:
  3218.       sprintf(Result, "\\zqppp %s",
  3219.           ValueString(STR1, ThisNote.NoteVal, PieceContr, AKey, true));
  3220.       break;
  3221.  
  3222.     case CC:
  3223.       sprintf(Result, "\\zq %s",
  3224.           ValueString(STR1, ThisNote.NoteVal, PieceContr, AKey, true));
  3225.       break;
  3226.  
  3227.     case CCP:
  3228.       sprintf(Result, "\\zqp %s",
  3229.           ValueString(STR1, ThisNote.NoteVal, PieceContr, AKey, true));
  3230.       break;
  3231.  
  3232.     case CC3:
  3233.       sprintf(Result, "\\zq %s",
  3234.           ValueString(STR1, ThisNote.NoteVal, PieceContr, AKey, true));
  3235.       break;
  3236.  
  3237.     case CCC:
  3238.       sprintf(Result, "\\zq %s",
  3239.           ValueString(STR1, ThisNote.NoteVal, PieceContr, AKey, true));
  3240.       break;
  3241.  
  3242.     case CCCP:
  3243.       sprintf(Result, "\\zqp %s",
  3244.           ValueString(STR1, ThisNote.NoteVal, PieceContr, AKey, true));
  3245.       break;
  3246.  
  3247.     case CCC3:
  3248.       sprintf(Result, "\\zq %s",
  3249.           ValueString(STR1, ThisNote.NoteVal, PieceContr, AKey, true));
  3250.       break;
  3251.  
  3252.     case CCCC:
  3253.       sprintf(Result, "\\zq %s",
  3254.           ValueString(STR1, ThisNote.NoteVal, PieceContr, AKey, true));
  3255.       break;
  3256.  
  3257.     case CCCCP:
  3258.       sprintf(Result, "\\zqp %s",
  3259.           ValueString(STR1, ThisNote.NoteVal, PieceContr, AKey, true));
  3260.       break;
  3261.  
  3262.     case CCCC3:
  3263.       sprintf(Result, "\\zq %s",
  3264.           ValueString(STR1, ThisNote.NoteVal, PieceContr, AKey, true));
  3265.       break;
  3266.     }/* case */
  3267.     break;
  3268.  
  3269.   case VOID:
  3270.     strcpy(Result, "");
  3271.     break;
  3272.  
  3273.   case REST:
  3274.     RestString(Result, ThisNote.NoteType, Clef);
  3275.     break;
  3276.  
  3277.   case TXT:
  3278.     sprintf(Result, "\\uptext{%s}", ThisNote.MetaTxt);
  3279.     break;
  3280.  
  3281.   case PEDAL:
  3282.     if (ThisNote.Velocity > 0)
  3283.       strcpy(Result, "\\PED");
  3284.     else
  3285.       strcpy(Result, "\\DEP");
  3286.     break;
  3287.   }
  3288.   return Result;
  3289. }  /* ChordNote2String */
  3290.  
  3291. /*  variables for BeamNote2String:
  3292. struct LOC_BeamNote2String {
  3293.   BeamRecord ThisBeam;
  3294. } ; */
  3295.  
  3296. /*------------------------------*/
  3297.  Char HOrB(LINK)
  3298. struct LOC_BeamNote2String *LINK;
  3299. {
  3300.   /*------------------------------*/
  3301.   if (LINK->ThisBeam.Orient == UP)
  3302.     return 'h';
  3303.   else
  3304.     return 'b';
  3305. }
  3306.  
  3307. /*------------------------------*/
  3308.  Char BNo(LINK)
  3309. struct LOC_BeamNote2String *LINK;
  3310. {
  3311.   /*------------------------------*/
  3312.   Char Tmp[256];
  3313.  
  3314.   sprintf(Tmp, "%1d", LINK->ThisBeam.Numb);
  3315.   if (strlen(Tmp) > 1)
  3316.     WriteDebugInfo("Warning: found a beam number bigger than 9 !");
  3317.   return (Tmp[0]);
  3318. }
  3319.  
  3320.  
  3321.  
  3322. /**************************************************************/
  3323.  Char *BeamNote2String(Result, ThisNote, ThisBeam_, Clef, AKey)
  3324. Char *Result;
  3325. NoteRecord ThisNote;
  3326. BeamRecord ThisBeam_;
  3327. ClefType Clef;
  3328. AccKeyType *AKey;
  3329. {
  3330.   /**************************************************************/
  3331.   struct LOC_BeamNote2String V;
  3332.   Char TmpStr[26];
  3333.   Char STR1[25], STR3[25];
  3334.  
  3335.   V.ThisBeam = ThisBeam_;
  3336.   switch (ThisNote.Event) {
  3337.  
  3338.   case NOTEON:
  3339.   case NOTEOFF:
  3340.     switch (ThisNote.NoteType) {
  3341.  
  3342.     case C:
  3343.     case C3:
  3344.     case CC:
  3345.     case CC3:
  3346.     case CCC:
  3347.     case CCC3:
  3348.     case CCCC:
  3349.     case CCCC3:
  3350.       sprintf(TmpStr, "\\q%c%c%s",
  3351.           HOrB(&V), BNo(&V),
  3352.           ValueString(STR1, ThisNote.NoteVal, PieceContr, AKey, true));
  3353.       break;
  3354.  
  3355.     case CP:
  3356.     case CCP:
  3357.     case CCCP:
  3358.     case CCCCP:
  3359.       sprintf(TmpStr, "\\pt %s\\q%c%c%s",
  3360.           ValueString(STR1, ThisNote.NoteVal, PieceContr, AKey, false),
  3361.           HOrB(&V), BNo(&V),
  3362.           ValueString(STR3, ThisNote.NoteVal, PieceContr, AKey, true));
  3363.       break;
  3364.  
  3365.     case CPP:
  3366.       sprintf(TmpStr, "\\ppt %s\\q%c%c%s",
  3367.           ValueString(STR1, ThisNote.NoteVal, PieceContr, AKey, false),
  3368.           HOrB(&V), BNo(&V),
  3369.           ValueString(STR3, ThisNote.NoteVal, PieceContr, AKey, true));
  3370.       break;
  3371.  
  3372.     case CPPP:
  3373.       sprintf(TmpStr, "\\pppt %s\\q%c%c%s",
  3374.           ValueString(STR1, ThisNote.NoteVal, PieceContr, AKey, false),
  3375.           HOrB(&V), BNo(&V),
  3376.           ValueString(STR3, ThisNote.NoteVal, PieceContr, AKey, true));
  3377.       break;
  3378.  
  3379.     default:
  3380.       sprintf(TmpStr, "??%c%c%s",
  3381.           HOrB(&V), BNo(&V),
  3382.           ValueString(STR1, ThisNote.NoteVal, PieceContr, AKey, true));
  3383.       WriteDebugInfo(
  3384.     "Warning : found a note longer than an eighth note in a beam !");
  3385.       break;
  3386.     }/* case */
  3387.     break;
  3388.  
  3389.   case VOID:
  3390.     *TmpStr = '\0';
  3391.     break;
  3392.  
  3393.   case REST:
  3394.     RestString(TmpStr, ThisNote.NoteType, Clef);
  3395.     break;
  3396.  
  3397.   case TXT:
  3398.     sprintf(TmpStr, "\\uptext{%s}", ThisNote.MetaTxt);
  3399.     break;
  3400.  
  3401.   case PEDAL:
  3402.     if (ThisNote.Velocity > 0)
  3403.       strcpy(TmpStr, "\\PED");
  3404.     else
  3405.       strcpy(TmpStr, "\\DEP");
  3406.     break;
  3407.   }/* with thisnote */
  3408.   return strcpy(Result, TmpStr);
  3409. }  /* BeamNote2String */
  3410.  
  3411.  
  3412.  
  3413. /*****************************************************************/
  3414.  Char *InitBeam(Result, ThisBeam, ForceZero, AKey)
  3415. Char *Result;
  3416. BeamRecord ThisBeam;
  3417. boolean ForceZero;
  3418. AccKeyType *AKey;
  3419. {
  3420.   /*****************************************************************/
  3421. /*  Char TmpStr[26]; */
  3422.   Char IndxStr[3];
  3423. /*  Char STR1[256], STR2[42]; */
  3424.  
  3425.   sprintf(IndxStr, "%1d", ThisBeam.Numb);
  3426.   strcpy(TmpStr, "\\i");
  3427.   switch (ThisBeam.NoteType) {
  3428.  
  3429.   case C:
  3430.   case C3:
  3431.   case CP:
  3432.   case CPP:
  3433.   case CPPP:
  3434.     strcat(TmpStr, "b");
  3435.     break;
  3436.  
  3437.   case CC:
  3438.   case CC3:
  3439.   case CCP:
  3440.     strcat(TmpStr, "bb");
  3441.     break;
  3442.  
  3443.   case CCC:
  3444.   case CCC3:
  3445.   case CCCP:
  3446.     strcat(TmpStr, "bbb");
  3447.     break;
  3448.  
  3449.   case CCCC:
  3450.   case CCCC3:
  3451.   case CCCCP:
  3452.     strcat(TmpStr, "bbbb");
  3453.     break;
  3454.   }/* case */
  3455.   if (ThisBeam.Orient == UP)
  3456.     sprintf(TmpStr + strlen(TmpStr), "u%s", IndxStr);
  3457.   else
  3458.     sprintf(TmpStr + strlen(TmpStr), "l%s", IndxStr);
  3459.  
  3460.   sprintf(TmpStr + strlen(TmpStr), "%s{",
  3461.       ValueString(STR1, ThisBeam.Pitch, PieceContr, AKey, false));
  3462.  
  3463.   /* determine the slope */
  3464.   if (ForceZero)
  3465.     strcpy(IndxStr, "0");
  3466.   else {
  3467.     switch (ThisBeam.Slope) {
  3468.  
  3469.     case -20:
  3470.     case -19:
  3471.     case -18:
  3472.       sprintf(IndxStr, "%2d", -8);
  3473.       break;
  3474.  
  3475.     case -17:
  3476.     case -16:
  3477.     case -15:
  3478.       sprintf(IndxStr, "%2d", -7);
  3479.       break;
  3480.  
  3481.     case -14:
  3482.     case -13:
  3483.     case -12:
  3484.       sprintf(IndxStr, "%2d", -6);
  3485.       break;
  3486.  
  3487.     case -11:
  3488.     case -10:
  3489.       sprintf(IndxStr, "%2d", -5);
  3490.       break;
  3491.  
  3492.     case -9:
  3493.     case -8:
  3494.       sprintf(IndxStr, "%2d", -4);
  3495.       break;
  3496.  
  3497.     case -7:
  3498.     case -6:
  3499.       sprintf(IndxStr, "%2d", -3);
  3500.       break;
  3501.  
  3502.     case -5:
  3503.     case -4:
  3504.       sprintf(IndxStr, "%2d", -2);
  3505.       break;
  3506.  
  3507.     case -3:
  3508.     case -2:
  3509.       sprintf(IndxStr, "%2d", -1);
  3510.       break;
  3511.  
  3512.     case -1:
  3513.     case 0:
  3514.     case 1:
  3515.       sprintf(IndxStr, "%1d", 0);
  3516.       break;
  3517.  
  3518.     case 2:
  3519.     case 3:
  3520.       sprintf(IndxStr, "%1d", 1);
  3521.       break;
  3522.  
  3523.     case 4:
  3524.     case 5:
  3525.       sprintf(IndxStr, "%1d", 2);
  3526.       break;
  3527.  
  3528.     case 6:
  3529.     case 7:
  3530.       sprintf(IndxStr, "%1d", 3);
  3531.       break;
  3532.  
  3533.     case 8:
  3534.     case 9:
  3535.       sprintf(IndxStr, "%1d", 4);
  3536.       break;
  3537.  
  3538.     case 10:
  3539.     case 11:
  3540.       sprintf(IndxStr, "%1d", 5);
  3541.       break;
  3542.  
  3543.     case 12:
  3544.     case 13:
  3545.     case 14:
  3546.       sprintf(IndxStr, "%1d", 6);
  3547.       break;
  3548.  
  3549.     case 15:
  3550.     case 16:
  3551.     case 17:
  3552.       sprintf(IndxStr, "%1d", 7);
  3553.       break;
  3554.  
  3555.     case 18:
  3556.     case 19:
  3557.     case 20:
  3558.       sprintf(IndxStr, "%1d", 8);
  3559.       break;
  3560.  
  3561.     default:
  3562.       if (ThisBeam.Slope >= -127 && ThisBeam.Slope <= -21)
  3563.     sprintf(IndxStr, "%2d", -9);
  3564.       else if (ThisBeam.Slope >= 21 && ThisBeam.Slope <= 127)
  3565.     sprintf(IndxStr, "%1d", 9);
  3566.       break;
  3567.     }
  3568.   }
  3569.   sprintf(TmpStr + strlen(TmpStr), "%s}", IndxStr);   /* With */
  3570.   sprintf(STR1, "Init beam with %s", TmpStr);
  3571.   WriteDebugInfo(STR1);
  3572.   return strcpy(Result, TmpStr);
  3573. }  /* InitBeam */
  3574.  
  3575. /*****************************************************/
  3576.  Char *PartialBeam(Result, ThisBeam)
  3577. Char *Result;
  3578. BeamRecord ThisBeam;
  3579. {
  3580.   /*****************************************************/
  3581.   Char IndxStr[3];
  3582.   Char TermBeam[26];
  3583. /*  Char STR1[54]; */
  3584.  
  3585.   sprintf(IndxStr, "%1d", ThisBeam.Numb);
  3586.   strcpy(TermBeam, "\\rlap{\\qsk\\t");
  3587.   switch (ThisBeam.NoteType) {
  3588.  
  3589.   case C:
  3590.   case C3:
  3591.   case CP:
  3592.   case CPP:
  3593.   case CPPP:
  3594.     strcat(TermBeam, "b");
  3595.     break;
  3596.  
  3597.   case CC:
  3598.   case CC3:
  3599.   case CCP:
  3600.     strcat(TermBeam, "bb");
  3601.     break;
  3602.  
  3603.   case CCC:
  3604.   case CCC3:
  3605.   case CCCP:
  3606.     strcat(TermBeam, "bbb");
  3607.     break;
  3608.  
  3609.   case CCCC:
  3610.   case CCCC3:
  3611.   case CCCCP:
  3612.     strcat(TermBeam, "bbbb");
  3613.     break;
  3614.   }/* case */
  3615.  
  3616.   if (ThisBeam.Orient == UP)
  3617.     sprintf(TermBeam + strlen(TermBeam), "u%s}", IndxStr);
  3618.   else
  3619.     sprintf(TermBeam + strlen(TermBeam), "l%s}", IndxStr);
  3620.   sprintf(STR1, "Partial terminate beam with %s", TermBeam);
  3621.   WriteDebugInfo(STR1);
  3622.   return strcpy(Result, TermBeam);
  3623. }  /* PartialBeam */
  3624.  
  3625.  
  3626. /*****************************************************/
  3627.  Char *TerminateBeam(Result, ThisBeam)
  3628. Char *Result;
  3629. BeamRecord ThisBeam;
  3630. {
  3631.   /*****************************************************/
  3632.   Char IndxStr[3];
  3633.   Char TermBeam[26];
  3634. /*  Char STR1[48]; */
  3635.  
  3636.   if (ThisBeam.Orient == UP)
  3637.     sprintf(TermBeam, "\\tbu%1d", ThisBeam.Numb);
  3638.   else
  3639.     sprintf(TermBeam, "\\tbl%1d", ThisBeam.Numb);
  3640.   sprintf(STR1, "Terminating beam with %s", TermBeam);
  3641.   WriteDebugInfo(STR1);
  3642.   return strcpy(Result, TermBeam);
  3643. }  /* Terminate Beam */
  3644.  
  3645. /***********************************************************/
  3646.  Char *ChainBeam(Result, ThisBeam, NextBeam)
  3647. Char *Result;
  3648. BeamRecord ThisBeam, NextBeam;
  3649. {
  3650.   /***********************************************************/
  3651.   Char IndxStr[3];
  3652. /*  Char TmpStr[26];
  3653.   Char STR1[46]; */
  3654.  
  3655.   if ((long)NextBeam.NoteType > (long)ThisBeam.NoteType) {   /* With */
  3656.     sprintf(IndxStr, "%1d", NextBeam.Numb);
  3657.  
  3658.     if (NextBeam.NoNotes == 1)
  3659.       /* there is only one note of higher type in next beam */
  3660.         strcpy(TmpStr, "\\t");
  3661.       /* instead of initializing higher order beam we insert */
  3662.     else  /* a terminate beam which draws the flags at the back  */
  3663.       strcpy(TmpStr, "\\n");
  3664.     /* of the note                                         */
  3665.  
  3666.     switch (NextBeam.NoteType) {
  3667.  
  3668.     case C:
  3669.     case C3:
  3670.     case CP:
  3671.     case CPP:
  3672.     case CPPP:
  3673.       strcat(TmpStr, "b");
  3674.       break;
  3675.  
  3676.     case CC:
  3677.     case CC3:
  3678.     case CCP:
  3679.       strcat(TmpStr, "bb");
  3680.       break;
  3681.  
  3682.     case CCC:
  3683.     case CCC3:
  3684.     case CCCP:
  3685.       strcat(TmpStr, "bbb");
  3686.       break;
  3687.  
  3688.     case CCCC:
  3689.     case CCCC3:
  3690.     case CCCCP:
  3691.       strcat(TmpStr, "bbb");
  3692.       break;
  3693.     }/* case */
  3694.     if (ThisBeam.Orient == UP)   /* With */
  3695.       sprintf(TmpStr + strlen(TmpStr), "u%s", IndxStr);
  3696.     else
  3697.       sprintf(TmpStr + strlen(TmpStr), "l%s", IndxStr);
  3698.  
  3699.   } else {
  3700.     sprintf(IndxStr, "%1d", NextBeam.Numb);
  3701.     strcpy(TmpStr, "\\t");
  3702.     switch (NextBeam.NoteType) {
  3703.  
  3704.     case C:
  3705.     case C3:
  3706.     case CP:
  3707.     case CPP:
  3708.     case CPPP:
  3709.       strcat(TmpStr, "bb");
  3710.       break;
  3711.  
  3712.     case CC:
  3713.     case CC3:
  3714.     case CCP:
  3715.       strcat(TmpStr, "bbb");
  3716.       break;
  3717.  
  3718.     case CCC:
  3719.     case CCC3:
  3720.     case CCCP:
  3721.       strcat(TmpStr, "bbbb");
  3722.       break;
  3723.  
  3724.     case CCCC:
  3725.     case CCCC3:
  3726.     case CCCCP:
  3727.       WriteDebugInfo("This cannot happen...!, error in CHaining beam");
  3728.       break;
  3729.     }/* case */
  3730.     if (ThisBeam.Orient == UP)
  3731.       sprintf(TmpStr + strlen(TmpStr), "u%s", IndxStr);
  3732.     else
  3733.       sprintf(TmpStr + strlen(TmpStr), "l%s", IndxStr);
  3734.   }
  3735.  
  3736.   sprintf(STR1, "Chaining beam with %s", TmpStr);
  3737.   WriteDebugInfo(STR1);
  3738.   return strcpy(Result, TmpStr);
  3739.  
  3740.  
  3741. }  /* ChainBeam */
  3742.  
  3743.  
  3744. /*****************************************************************/
  3745.  Char *InitSlurr(Result, ThisSlurr, AKey)
  3746. Char *Result;
  3747. SlurrRecord ThisSlurr;
  3748. AccKeyType *AKey;
  3749. {
  3750.   /*****************************************************************/
  3751. /*  Char TmpStr[26]; */
  3752.   Char IndxStr[3];
  3753. /*  Char STR1[256];
  3754.   Char STR2[256]; */
  3755.  
  3756.   sprintf(IndxStr, "%1d", ThisSlurr.Numb1);
  3757.   sprintf(TmpStr, "\\itenu%s%s",
  3758.       IndxStr,
  3759.       ValueString(STR2, ThisSlurr.NoteVal, PieceContr, AKey, false));
  3760.   sprintf(STR1, "Init slurr with %s", TmpStr);
  3761.   WriteDebugInfo(STR1);
  3762.   return strcpy(Result, TmpStr);
  3763. }  /* InitSlurr*/
  3764.  
  3765. /***********************************************************/
  3766.  Char *TerminateSlurr(Result, ThisSlurr)
  3767. Char *Result;
  3768. SlurrRecord *ThisSlurr;
  3769. {
  3770.   /***********************************************************/
  3771.   Char IndxStr[3];
  3772. /*  Char TmpStr[26];
  3773.   Char STR1[50]; */
  3774.  
  3775.   sprintf(IndxStr, "%1d", ThisSlurr->Numb2);
  3776.   sprintf(TmpStr, "\\tten%s", IndxStr);
  3777.   sprintf(STR1, "Terminating slurr with %s", TmpStr);
  3778.   WriteDebugInfo(STR1);
  3779.   if (ThisSlurr->KindOf == ENDSLUR)
  3780.     ThisSlurr->Occupied = false;
  3781.   return strcpy(Result, TmpStr);
  3782. }  /* Terminate Slurr */
  3783.  
  3784.  
  3785.  
  3786.  
  3787.  
  3788. /****************************************************/
  3789.  Void FindMeasureParts(ThisMeasure)
  3790. unsigned int ThisMeasure;
  3791. {
  3792.   /****************************************************/
  3793.   MeasureTime ST, ET, TET, DT;
  3794.   long i, curtrack;
  3795.   NoteRecord *N, *P, *Q_;
  3796.   boolean Done, PartEmpty;
  3797.   long t1, t2, FORLIM;
  3798.   TrackRecord *WITH;
  3799. /*  Char STR1[256], STR2[256];
  3800.   Char STR3[28]; */
  3801.   long FORLIM1;
  3802.  
  3803.   FORLIM = ntracks;
  3804.   for (curtrack = 1; curtrack <= FORLIM; curtrack++) {   /* with curtrack */
  3805.     WITH = &TrackArray[curtrack - 1];
  3806.     sprintf(STR1, "Finding parts in track %3ld", curtrack);
  3807.     WriteDebugInfo(STR1);
  3808.     FirstNote(WITH->NoteList, &N);
  3809.     Q_ = N;
  3810.     LastNote(WITH->NoteList, &P);
  3811.     SetTim(&ST, ThisMeasure, 0);
  3812.     SetTim(&ET, ThisMeasure, (int)PieceContr.TicksPerMeasure);
  3813.     SetTim(&DT, 0, PieceContr.PartTime);
  3814.     AddTime(ST, DT, &TET);
  3815.     if (N == P) {
  3816.       WriteDebugInfo("Only one event in this track and measure ");
  3817.       switch (N->Event) {
  3818.  
  3819.       case NOTEON:
  3820.       case NOTEOFF:
  3821.     sprintf(STR1, "Note %3d", N->NoteVal);
  3822.     WriteDebugInfo(STR1);
  3823.     break;
  3824.  
  3825.       case REST:
  3826.     sprintf(STR1, "Rest of type %3ld", (long)N->NoteType);
  3827.     WriteDebugInfo(STR1);
  3828.     break;
  3829.  
  3830.       case TXT:
  3831.     sprintf(STR1, "Text : %s", N->MetaTxt);
  3832.     WriteDebugInfo(STR1);
  3833.     break;
  3834.  
  3835.       case VOID:
  3836.     WriteDebugInfo("Void event ");
  3837.     break;
  3838.  
  3839.       case PEDAL:
  3840.     WriteDebugInfo("Pedal event");
  3841.     break;
  3842.       }
  3843.  
  3844.       switch (N->Event) {
  3845.  
  3846.       case NOTEON:
  3847.       case NOTEOFF:
  3848.       case TXT:
  3849.     WITH->PartStart[0] = N;
  3850.     WITH->PartEnd[0] = N;
  3851.     FORLIM1 = PieceContr.nparts;
  3852.     for (i = 1; i < FORLIM1; i++) {
  3853.       /* Reset further starts and ends..., but why here ... ? */
  3854.       WITH->PartStart[i] = NULL;
  3855.       WITH->PartEnd[i] = NULL;
  3856.     }
  3857.     break;
  3858.  
  3859.       case REST:
  3860.     FORLIM1 = PieceContr.nparts;
  3861.     for (i = 0; i < FORLIM1; i++) {
  3862.       WITH->PartStart[i] = NULL;
  3863.       WITH->PartEnd[i] = NULL;
  3864.     }
  3865.     i = PieceContr.nparts / 2;
  3866.     WITH->PartStart[i - 1] = N;
  3867.     WITH->PartEnd[i - 1] = N;
  3868.     break;
  3869.  
  3870.       case VOID:
  3871.     FORLIM1 = PieceContr.nparts;
  3872.     for (i = 0; i < FORLIM1; i++) {
  3873.       WITH->PartStart[i] = NULL;
  3874.       WITH->PartEnd[i] = NULL;
  3875.     }
  3876.     break;
  3877.       }/* case */
  3878.     } else {  /* N<>P */
  3879.       FORLIM1 = PieceContr.nparts;
  3880.       for (i = 0; i < FORLIM1; i++) {
  3881.     sprintf(STR1, "In part %3ld following events:", i + 1);
  3882.     WriteDebugInfo(STR1);
  3883.     PartEmpty = true;
  3884.     WITH->PartStart[i] = NULL;
  3885.     WITH->PartEnd[i] = NULL;
  3886.     Done = false;
  3887.     t1 = TimeDiff(ST, N->StartTime);
  3888.     t2 = TimeDiff(TET, N->StartTime);
  3889.     /* does not stop at end of measure */
  3890.     while (t1 <= 0 && t2 > 0 && !Done) {   /* Else */
  3891.       switch (PartEmpty) {
  3892.  
  3893.       case true:
  3894.         WITH->PartStart[i] = N;
  3895.         WITH->PartEnd[i] = N;
  3896.         PartEmpty = false;
  3897.         break;
  3898.  
  3899.       case false:
  3900.         WITH->PartEnd[i] = N;
  3901.         break;
  3902.       }/* case */
  3903.       switch (N->Event) {
  3904.  
  3905.       case NOTEON:
  3906.       case NOTEOFF:
  3907.         sprintf(STR1, "Note %3d", N->NoteVal);
  3908.         WriteDebugInfo(STR1);
  3909.         break;
  3910.  
  3911.       case REST:
  3912.         sprintf(STR1, "Rest of type %3ld", (long)N->NoteType);
  3913.         WriteDebugInfo(STR1);
  3914.         break;
  3915.  
  3916.       case TXT:
  3917.         sprintf(STR1, "Text : %s", N->MetaTxt);
  3918.         WriteDebugInfo(STR1);
  3919.         break;
  3920.         /* VOID           : Warning('Whoops, a void event in part....'); */
  3921.       }
  3922.       NextNote(N, &N);
  3923.       if (N == Q_)
  3924.         Done = true;
  3925.       t1 = TimeDiff(ST, N->StartTime);
  3926.       t2 = TimeDiff(TET, N->StartTime);
  3927.     }  /* while */
  3928.     memmove(&ST,&TET, sizeof(MeasureTime));
  3929.     AddTime(ST, DT, &TET);
  3930.       }  /* for next i */
  3931.     }  /* Else: N<>P */
  3932.   }
  3933.   WriteDebugInfo("Ready finding parts in this measure");
  3934. }  /* FindMeasureParts */
  3935.  
  3936. /*  variables for PartCreateMeasure: 
  3937. struct LOC_PartCreateMeasure {
  3938.   NoteRecord *N;
  3939.   long curtr, EventCnt;
  3940.   boolean BeamsOccured;
  3941. } ; */
  3942.  
  3943.  
  3944. /*-------------------------------*/
  3945.  Char *Seperator(Result, LINK)
  3946. Char *Result;
  3947. struct LOC_PartCreateMeasure *LINK;
  3948. {
  3949.   /*-------------------------------*/
  3950.   Char TmpStr[256];
  3951.  
  3952.   *TmpStr = '\0';
  3953.   if (LINK->curtr == ntracks) {
  3954.     /* we are at the end of the current range ...*/
  3955.       if (ntracks <= 1) {  /* curtr=ntracks */
  3956.       *TmpStr = '\0';
  3957.       return strcpy(Result, TmpStr);
  3958.     }
  3959.     if (TrackArray[TrackOrder[ntracks - 1] - 1].Skip== true ||
  3960.     TrackArray[TrackOrder[ntracks - 2] - 1].Skip == true)
  3961.       return strcpy(Result, TmpStr);
  3962.     if (TrackArray[TrackOrder[ntracks - 1] - 1].Instrument==true &&
  3963.     TrackArray[TrackOrder[ntracks - 2] - 1].Instrument==true)
  3964.       strcpy(TmpStr, "|");
  3965.     else
  3966.       strcpy(TmpStr, "&");
  3967.     return strcpy(Result, TmpStr);
  3968.   }
  3969.   if (LINK->curtr == 1) {  /* curtr=1 */
  3970.     *TmpStr = '\0';
  3971.     return strcpy(Result, TmpStr);
  3972.   }
  3973.   if (TrackArray[TrackOrder[LINK->curtr - 2] - 1].Skip)
  3974.     return strcpy(Result, TmpStr);
  3975.   if (TrackArray[TrackOrder[LINK->curtr - 1] - 1].Instrument == true&&
  3976.       TrackArray[TrackOrder[LINK->curtr - 2] - 1].Instrument ==true)
  3977.     strcpy(TmpStr, "|");
  3978.   else
  3979.     strcpy(TmpStr, "&");
  3980.   return strcpy(Result, TmpStr);
  3981.  
  3982.   /* curtr>1 & curtr<ntracks */
  3983. }  /* Seperator */
  3984.  
  3985.  
  3986. /*--------------------------------------------------------*/
  3987.  Char *GetNoteStr(Result, ThisTrack, LINK)
  3988. Char *Result;
  3989. TrackRecord *ThisTrack;
  3990. struct LOC_PartCreateMeasure *LINK;
  3991. {
  3992.   /*--------------------------------------------------------*/
  3993.   Char Astring[256];
  3994.   long j;
  3995.   MeasureTime TmpTime;
  3996.   SlurrRecord *WITH1;
  3997. /*  Char STR1[256]; */
  3998.  
  3999.   *Astring = '\0';
  4000.   SetTim(&TmpTime, (int)(MeasureCount + 1), 0);
  4001.  
  4002.   if (ThisTrack->Slurring) {
  4003.     j = IsSlurred(LINK->N, ThisTrack);
  4004.     if (j > 0) {
  4005.       WITH1 = &ThisTrack->SlurrArray[j - 1];
  4006.       switch (WITH1->KindOf) {
  4007.  
  4008.       case STARTSLUR:
  4009.     strcat(Astring, InitSlurr(STR1, ThisTrack->SlurrArray[j - 1],
  4010.                   &ThisTrack->AccKey));
  4011.     break;
  4012.  
  4013.       case REPEATSLUR:
  4014.     strcat(Astring, TerminateSlurr(STR1, &ThisTrack->SlurrArray[j - 1]));
  4015.     strcat(Astring, InitSlurr(STR1, ThisTrack->SlurrArray[j - 1],
  4016.                   &ThisTrack->AccKey));
  4017.     break;
  4018.  
  4019.       case ENDSLUR:
  4020.     strcat(Astring, TerminateSlurr(STR1, &ThisTrack->SlurrArray[j - 1]));
  4021.     break;
  4022.       }/* case */
  4023.     }
  4024.   }  /* slurring */
  4025.  
  4026.  
  4027.   if (ThisTrack->Beam) {
  4028.     LINK->BeamsOccured = true;
  4029.     if (LINK->N == ThisTrack->BeamArray[ThisTrack->BeamPt - 1].EndNote) {
  4030.       if (ThisTrack->BeamArray[ThisTrack->BeamPt - 1].Chain2Next) {
  4031.     strcat(Astring,
  4032.            ChainBeam(STR1, ThisTrack->BeamArray[ThisTrack->BeamPt - 1],
  4033.              ThisTrack->BeamArray[ThisTrack->BeamPt]));
  4034.  
  4035.     ThisTrack->BeamPt++;
  4036.  
  4037.     if (LINK->N == ThisTrack->BeamArray[ThisTrack->BeamPt - 1].EndNote)
  4038.           /* end this beam immediately */
  4039.         strcat(Astring, TerminateBeam(STR1,
  4040.              ThisTrack->BeamArray[ThisTrack->BeamPt - 1]));
  4041.  
  4042.       } else
  4043.     strcat(Astring,
  4044.       TerminateBeam(STR1, ThisTrack->BeamArray[ThisTrack->BeamPt - 1]));
  4045.     }
  4046.   }  /* if beam */
  4047.   else {
  4048.     if (LINK->N == ThisTrack->BeamArray[ThisTrack->BeamPt - 1].StartNote) {
  4049.       LINK->BeamsOccured = true;
  4050.       if (ThisTrack->BeamArray[ThisTrack->BeamPt - 1].NoNotes == 1 &&
  4051.       ThisTrack->BeamArray[ThisTrack->BeamPt - 1].Chain2Next  == true &&
  4052.       (long)ThisTrack->BeamArray[ThisTrack->BeamPt - 1].NoteType >
  4053.       (long)ThisTrack->BeamArray[ThisTrack->BeamPt].NoteType) {
  4054.     strcat(Astring,
  4055.            InitBeam(STR1, ThisTrack->BeamArray[ThisTrack->BeamPt],
  4056.             ThisTrack->ForceZeroBeams, &ThisTrack->AccKey));
  4057.     strcat(Astring,
  4058.            PartialBeam(STR1, ThisTrack->BeamArray[ThisTrack->BeamPt - 1]));
  4059.     ThisTrack->BeamPt++;
  4060.       } else
  4061.     strcat(Astring,
  4062.            InitBeam(STR1, ThisTrack->BeamArray[ThisTrack->BeamPt - 1],
  4063.             ThisTrack->ForceZeroBeams, &ThisTrack->AccKey));
  4064.       ThisTrack->Beam = true;
  4065.     }
  4066.   }
  4067.  
  4068.  
  4069.   if (ThisTrack->Chord) {   /* With thistrack */
  4070.     if (LINK->N != ThisTrack->ChordArray[ThisTrack->ChordPt - 1].EndNote) {
  4071.       strcat(Astring, ChordNote2String(STR1, *LINK->N, ThisTrack->Clef,
  4072.                        &ThisTrack->AccKey));
  4073.       return strcpy(Result, Astring);
  4074.     }
  4075.     ThisTrack->Chord = false;
  4076.     WriteDebugInfo("Hit the end of the chord");
  4077.     ThisTrack->ChordPt++;
  4078.     if (!ThisTrack->Beam) {
  4079.       strcat(Astring, Note2String(STR1, *LINK->N, ThisTrack->Clef,
  4080.                   &ThisTrack->AccKey));
  4081.       LINK->EventCnt++;
  4082.       return strcpy(Result, Astring);
  4083.     }
  4084.     LINK->BeamsOccured = true;
  4085.     strcat(Astring, BeamNote2String(STR1, *LINK->N,
  4086.          ThisTrack->BeamArray[ThisTrack->BeamPt - 1], ThisTrack->Clef,
  4087.          &ThisTrack->AccKey));
  4088.     LINK->EventCnt++;
  4089.     if (LINK->N == ThisTrack->BeamArray[ThisTrack->BeamPt - 1].EndNote) {
  4090.       ThisTrack->Beam = false;
  4091.       ThisTrack->BeamPt++;
  4092.     }
  4093.     return strcpy(Result, Astring);
  4094.   }  /* If NtArPoint... */
  4095.  
  4096.   if (LINK->N == ThisTrack->ChordArray[ThisTrack->ChordPt - 1].StartNote) {
  4097.     WriteDebugInfo("Hit start of chord ");
  4098.     ThisTrack->Chord = true;
  4099.     strcat(Astring, ChordNote2String(STR1, *LINK->N, ThisTrack->Clef,
  4100.                      &ThisTrack->AccKey));
  4101.     return strcpy(Result, Astring);
  4102.   }
  4103.   if (!ThisTrack->Beam) {
  4104.     strcat(Astring,
  4105.        Note2String(STR1, *LINK->N, ThisTrack->Clef, &ThisTrack->AccKey));
  4106.     LINK->EventCnt++;
  4107.     return strcpy(Result, Astring);
  4108.   }
  4109.   LINK->BeamsOccured = true;
  4110.   strcat(Astring, BeamNote2String(STR1, *LINK->N,
  4111.                   ThisTrack->BeamArray[ThisTrack->BeamPt - 1],
  4112.                   ThisTrack->Clef, &ThisTrack->AccKey));
  4113.   LINK->EventCnt++;
  4114.   LINK->BeamsOccured = true;
  4115.   if (LINK->N == ThisTrack->BeamArray[ThisTrack->BeamPt - 1].EndNote &&
  4116.       !ThisTrack->BeamArray[ThisTrack->BeamPt - 1].Chain2Next) {
  4117.     ThisTrack->Beam = false;
  4118.     ThisTrack->BeamPt++;
  4119.   }
  4120.   return strcpy(Result, Astring);
  4121.  
  4122.  
  4123.   /* Else */
  4124. }  /* GetNoteStr */
  4125.  
  4126. /****************************************************/
  4127.  Void PartCreateMeasure()
  4128. {
  4129.   /****************************************************/
  4130.   struct LOC_PartCreateMeasure V;
  4131.   long i;
  4132.   static Char Ms[MAXPARTS][512];
  4133.   long CurLength;
  4134.   static long MaxCnts[MAXPARTS];
  4135.   long FORLIM;
  4136.   TrackRecord *WITH;
  4137. /*  Char STR1[256], STR2[512]; */
  4138.  
  4139.  
  4140.   FORLIM = ntracks;
  4141.   for (i = 0; i < FORLIM; i++) {
  4142.     WITH = &TrackArray[i];
  4143.     WITH->Chord = false;
  4144.     WITH->Beam = false;
  4145.     WITH->ChordPt = 1;
  4146.     WITH->BeamPt = 1;
  4147.   }
  4148.  
  4149.   CurLength = 0;
  4150.  
  4151.   FORLIM = PieceContr.nparts;
  4152.   for (i = 0; i < FORLIM; i++) {
  4153.     MaxCnts[i] = 0;
  4154.     V.BeamsOccured = false;
  4155.     strcpy(Ms[i],"");
  4156.     for (V.curtr = ntracks; V.curtr >= 1; V.curtr--) {
  4157.       WITH = &TrackArray[TrackOrder[V.curtr - 1] - 1];
  4158.       V.EventCnt = 0;
  4159.       if (WITH->NoteList.Size > MeasureMaxCnt)
  4160.     MeasureMaxCnt = WITH->NoteList.Size;
  4161.       if (!WITH->Skip) {
  4162.     V.N = WITH->PartStart[i];
  4163.     if (V.N != NULL) {
  4164.       strcat(Ms[i],
  4165.          GetNoteStr(STR1, &TrackArray[TrackOrder[V.curtr - 1] - 1],
  4166.                 &V));
  4167.       while (V.N != WITH->PartEnd[i]) {
  4168.         NextNote(V.N, &V.N);
  4169.         strcat(Ms[i],
  4170.            GetNoteStr(STR1, &TrackArray[TrackOrder[V.curtr - 1] - 1],
  4171.                   &V));
  4172.       }
  4173.     }
  4174.       }
  4175.       strcat(Ms[i], Seperator(STR1, &V));
  4176.  
  4177.       if (V.EventCnt > MaxCnts[i])
  4178.     MaxCnts[i] = V.EventCnt;
  4179.  
  4180.     }
  4181.  
  4182.     /* MaxCnts[i] contains the maximum number of notes in any of the tracks' parts */
  4183.     /* we use it to update the total         */
  4184.     /* cumulative length of the score line */
  4185.  
  4186.  
  4187.     if (V.BeamsOccured) {
  4188.       sprintf(STR2, "\\NOtes%s\\enotes\\relax", Ms[i]);
  4189.       strcpy(Ms[i], STR2);
  4190.       CurLength += MaxCnts[i] * ElemSkip * 2;
  4191.     } else {
  4192.       switch (MaxCnts[i]) {
  4193.  
  4194.       case 0:
  4195.     break;
  4196.     /* empty parts are not written ... */
  4197.  
  4198.       case 1:
  4199.       case 2:
  4200.     sprintf(STR1, "\\NOtes%s\\enotes\\relax", Ms[i]);
  4201.     strcpy(Ms[i], STR1);
  4202.     CurLength += MaxCnts[i] * ElemSkip * 2;
  4203.     break;
  4204.  
  4205.       case 3:
  4206.       case 4:
  4207.       case 5:
  4208.     sprintf(STR2, "\\Notes%s\\enotes\\relax", Ms[i]);
  4209.     strcpy(Ms[i], STR2);
  4210.     CurLength += (long)floor(1.4 * MaxCnts[i] * ElemSkip + 0.5);
  4211.     break;
  4212.  
  4213.       case 6:
  4214.       case 7:
  4215.       case 8:
  4216.       case 9:
  4217.       case 10:
  4218.     sprintf(STR1, "\\notes%s\\enotes\\relax", Ms[i]);
  4219.     strcpy(Ms[i], STR1);
  4220.     CurLength += MaxCnts[i] * ElemSkip;
  4221.     break;
  4222.  
  4223.       case 11:
  4224.       case 12:
  4225.       case 13:
  4226.       case 14:
  4227.       case 15:
  4228.     sprintf(STR2, "\\notes%s\\enotes\\relax", Ms[i]);
  4229.     strcpy(Ms[i], STR2);
  4230.     CurLength += MaxCnts[i] * ElemSkip;
  4231.     break;
  4232.  
  4233.       case 16:
  4234.       case 17:
  4235.       case 18:
  4236.       case 19:
  4237.       case 20:
  4238.     sprintf(STR1, "\\notes%s\\enotes\\relax", Ms[i]);
  4239.     strcpy(Ms[i], STR1);
  4240.     CurLength += MaxCnts[i] * ElemSkip;
  4241.     break;
  4242.  
  4243.       default:
  4244.     sprintf(STR2, "\\notes%s\\enotes\\relax", Ms[i]);
  4245.     strcpy(Ms[i], STR2);
  4246.     CurLength += MaxCnts[i] * ElemSkip;
  4247.     break;
  4248.       }/* case */
  4249.     }
  4250.  
  4251.     if (i + 1 > 1) {
  4252.       if (!V.BeamsOccured) {
  4253.     sprintf(STR2, "\\temps%s", Ms[i]);
  4254.     strcpy(Ms[i], STR2);
  4255.       }
  4256.     }
  4257.  
  4258.   }  /* For Next nparts */
  4259.  
  4260.   /* All parts are processed, a full measure has been written to disk   */
  4261.   /* Now we must find out if we have to write a \alapage and \alaligne  */
  4262.   /* CumLength now contains the length of the total lines               */
  4263.   if (MeasureCount > 0) {
  4264.     sprintf(STR1, "Curlength=%3ldpt, Cumlength=%3ldpt, Cumheight=%3ld",
  4265.         CurLength,CumLength,CumHeight);
  4266.     WriteDebugInfo(STR1);
  4267.     if (CumLength + CurLength >= ScoreWidth) {
  4268.       if (CumHeight + ScoreSep + LineHeight * (ntracks - NoOfSkips) >= ScoreHeight) {
  4269.     fprintf(TexFile, "\\alapage\n");
  4270.     NoOfPages++;
  4271.     CumHeight = ScoreSep + LineHeight * (ntracks - NoOfSkips) + 200;
  4272.     CumLength = Indent + CurLength;
  4273.     WriteDebugInfo("so... inserting \\alapage");
  4274.       } else {
  4275.     fprintf(TexFile, "\\alaligne\n");
  4276.     CumHeight += ScoreSep + LineHeight * (ntracks - NoOfSkips);
  4277.     CumLength = Indent + CurLength;
  4278.     WriteDebugInfo("so... inserting \\aligne");
  4279.       }
  4280.     } else
  4281.       if (!ChangedContext) {
  4282.      fprintf(TexFile, "\\barre\n");
  4283.      CumLength += BarIndent + CurLength;
  4284.      WriteDebugInfo("so... inserting \\barre");
  4285.       }
  4286.   }  /* If MeasureCount>0 */
  4287.   else  /* MeasureCOunt=0 */
  4288.     CumLength += ElemSkip + CurLength;
  4289.  
  4290.   /* Reset the ChangedCOntext flag to disable its effect in writing the \barre */
  4291.   ChangedContext=FALSE;
  4292.  
  4293.  
  4294.   FORLIM = PieceContr.nparts;
  4295.   for (i = 0; i < FORLIM; i++) {
  4296.     if (MaxCnts[i] > 0) {
  4297.       fprintf(TexFile, "%s\n", Ms[i]);
  4298.       sprintf(STR1, "Tail of MeasureString : %s", Ms[i]);
  4299.       WriteDebugInfo(STR1);
  4300.     } else
  4301.       WriteDebugInfo("Empty part ");
  4302.   }
  4303.  
  4304. }  /* PartCreateMeasure */
  4305.  
  4306. /**********************************************/
  4307.  Void CheckControls(ThisMsre)
  4308. long ThisMsre;
  4309. {   /* TrackArray record 1 contains META events */
  4310.   /**********************************************/
  4311.   NoteRecord *N;
  4312.   TrackRecord *WITH;
  4313.  
  4314.   WITH = TrackArray;
  4315.   if (WITH->NoteList.Size <= 0)
  4316.       /* we assume that there is only one control */
  4317.       {  /* per measure                              */
  4318.     return;
  4319.   }  /* If */
  4320.   FirstNote(WITH->NoteList, &N);
  4321.   if (N->StartTime.Measure != ThisMsre)
  4322.     return;
  4323.   switch (N->Event) {
  4324.  
  4325.   case KEYSIGN:
  4326.   case SIGNATURE:
  4327.     ChangeContext(N);
  4328.     break;
  4329.   }/* case */
  4330. }
  4331.  
  4332.  
  4333. /*************************************************************/
  4334. static Void InstallNewErrorExit()
  4335. {
  4336. /*************************************************************/
  4337. atexit(NewErrorExit);
  4338. }
  4339.  
  4340.   /**********************************************/
  4341.   /*                                            */
  4342.   /*           MAIN BLOCK                       */
  4343.   /*                                            */
  4344.   /**********************************************/
  4345.   long FORLIM;
  4346.   TrackRecord *WITH;
  4347.  
  4348. main(argc,argv)
  4349. int argc;
  4350. char *argv[];
  4351. {
  4352. #ifdef THINK_C
  4353. argc = ccommand(&argv);
  4354. #endif
  4355.  
  4356.   InstallNewErrorExit();
  4357.   DisplayLicense();
  4358.   Initialize(argc,argv);
  4359.   ReadString(TmpStr, &HlpFilRec, 4L);
  4360.   WriteDebugInfo(TmpStr);
  4361.   if (strcmp(TmpStr, "MThd"))
  4362.     ErrorExit(2L);
  4363.   ALongInt = ReadLongInt(&HlpFilRec);
  4364.   sprintf(STR1, "HeaderNo=%3ld", ALongInt);
  4365.   WriteDebugInfo(STR1);
  4366.   if (ALongInt != 6)
  4367.     ErrorExit(2L);
  4368.   FileFormat = ReadInteger(&HlpFilRec);
  4369.   sprintf(STR1, "MidiFile is in format type : %3d", (int)FileFormat);
  4370.   WriteDebugInfo(STR1);   /* this is OK */
  4371.   switch (FileFormat) {
  4372.  
  4373.   case 0:
  4374.     Warning("This is a type 0 MIDI file, no warranties about the result...");
  4375.     break;
  4376.  
  4377.   case 1:
  4378.     break;
  4379.   case 2:
  4380.     ErrorExit(5L);
  4381.     break;
  4382.   default:
  4383.     ErrorExit(5L);
  4384.     break;
  4385.   }
  4386.  
  4387.   ntracks = ReadInteger(&HlpFilRec);
  4388.   sprintf(STR1, " Found %3ld tracks in this file", ntracks);
  4389.   WriteDebugInfo(STR1);
  4390.   if (NoOfSkips > 0) {
  4391.     sprintf(STR1, "Skipping %3d of them", (int)NoOfSkips);
  4392.     WriteDebugInfo(STR1);
  4393.   }
  4394.   if (OrderIndex > 1) {
  4395.     if (OrderIndex != ntracks)
  4396.       ErrorExit(7L);
  4397.   }
  4398.   CumHeight = ScoreSep + LineHeight * (ntracks - NoOfSkips) + 300;
  4399.  
  4400.   WriteTexHeader();
  4401.   PieceContr.Division = ReadInteger(&HlpFilRec);
  4402.   sprintf(STR1, " Division : %3ld", PieceContr.Division);
  4403.   WriteDebugInfo(STR1);
  4404.   PieceContr.Num = 4;
  4405.   PieceContr.Den = 2;
  4406.   PieceContr.TicksPerMeasure = PieceContr.Division * PieceContr.Num * 4 /
  4407.                    Power(2, PieceContr.Den);
  4408.   sprintf(STR1, "Ticks per Measure :%3ld", PieceContr.TicksPerMeasure);
  4409.   WriteDebugInfo(STR1);
  4410.   PieceContr.PartTime = PieceContr.TicksPerMeasure / PieceContr.Num;
  4411.   PieceContr.nparts = PieceContr.TicksPerMeasure / PieceContr.PartTime;
  4412.   PieceContr.Twindow = PieceContr.Division / 16;
  4413.  
  4414.   InitFilePosns(ntracks);   /* find the starts of the tracks in the file */
  4415. #ifdef THINK_C
  4416. setvbuf(stdout,NULL,_IONBF,0);
  4417. #endif
  4418.   MeasureCount = -1;
  4419.   do {
  4420.     MeasureCount++;
  4421.     sprintf(STR1, " starting to read Measure %3d",(int)MeasureCount);
  4422.     WriteDebugInfo(STR1);
  4423.     printf("[%ld]",MeasureCount);
  4424.     if (MeasureCount > 0 && MeasureCount % 19 == 0)
  4425.       putchar('\n');
  4426.     FORLIM = ntracks;
  4427. /* p2c: tp_m2t13.pas, line 2958:
  4428.  * Note: Using % for possibly-negative arguments [317] */
  4429.     for (CurTrack = 1; CurTrack <= FORLIM; CurTrack++) {
  4430.       WITH = &TrackArray[CurTrack - 1];   /* With TrackArray */
  4431.       if (!EndOfTrackReached(&TrackArray[CurTrack - 1])) {
  4432.     sprintf(STR1, "Starting to read from track :%3ld", CurTrack);
  4433.     WriteDebugInfo(STR1);
  4434.     /* LastNoteOffTime.Measure:=MeasureCount; */
  4435.     /* to get a correct rest */
  4436.     /* LastNoteOffTime.Mpart:=0; */
  4437.  
  4438.     QuitTrack = false;
  4439.  
  4440.     /* Transfer all spilled events back to the note stack */
  4441.     if (WITH->SpillList.Size > 0) {
  4442.       sprintf(STR1, "Transfering %3d notes from spillist",
  4443.           WITH->SpillList.Size);
  4444.       WriteDebugInfo(STR1);
  4445.     }
  4446.     while (WITH->SpillList.Size > 0) {
  4447.       LastNote(WITH->SpillList, &N);
  4448.       Re_move(&WITH->SpillList, N);
  4449.       Append(&WITH->NoteList, N);
  4450.       sprintf(STR1, "Note : %3d from %3d:%3ld to %3d:%3ld",
  4451.           N->NoteVal,(int)N->StartTime.Measure,
  4452.           N->StartTime.MPart,
  4453.           (int)N->EndTime.Measure,
  4454.           N->EndTime.MPart);
  4455.       WriteDebugInfo(STR1);
  4456.  
  4457.       if (WITH->SpillList.Size == 0) {
  4458.         if (N->StartTime.Measure > MeasureCount)
  4459.           QuitTrack = true;
  4460.       }
  4461.     }
  4462.  
  4463.  
  4464.     if (!QuitTrack && !WITH->EndOfTrackRead) {
  4465.       sprintf(STR1,"FilePos for this track : %ld",GetFilePos(&TrackArray[CurTrack-1].FilRec));
  4466.       WriteDebugInfo(STR1);
  4467.       do {
  4468.         ReadDeltaTime(&TrackArray[CurTrack - 1]);
  4469.         if (WITH->Curtime.Measure > MeasureCount + 1 ||
  4470.         (WITH->Curtime.Measure == MeasureCount + 1 &&
  4471.          WITH->Curtime.MPart > QuantTime / 2))
  4472.           QuitTrack = true;
  4473.         ReadEvent(&TrackArray[CurTrack - 1]);
  4474.         SafetyCounter++;
  4475.       } while (!(QuitTrack== true || WITH->EndOfTrackRead == true));
  4476.     }
  4477.  
  4478.     /* Transfer SpillEvents to SpillList */
  4479.     /* only NoteOn can be transferred...*/
  4480.     /* a NoteOff can be maintained, but */
  4481.     /* note must than be slurred to     */
  4482.     /* next measure                     */
  4483.  
  4484.     /* removing notes to spillist not correct yet.... */
  4485.     /*  Hans : 24-3-92 */
  4486.  
  4487.     if (WITH->NoteList.Size > 0) {
  4488.       SetTim(&TempTime, (int)(MeasureCount + 1), 0);
  4489.       LastNote(WITH->NoteList, &N);
  4490.       while ((WITH->NoteList.Size > 0) &
  4491.          (TimeDiff(TempTime, N->StartTime) <= 0)) {
  4492.         sprintf(STR1, "Transfering note %3d to spillist",N->NoteVal);
  4493.         WriteDebugInfo(STR1);
  4494.         Re_move(&WITH->NoteList, N);
  4495.         Append(&WITH->SpillList, N);
  4496.         if (WITH->NoteList.Size > 0) {
  4497.           LastNote(WITH->NoteList, &N);
  4498.           sprintf(STR1, "Last note now : %3d", N->NoteVal);
  4499.           WriteDebugInfo(STR1);
  4500.         }
  4501.       }
  4502.     }
  4503.  
  4504.       } else {
  4505.     sprintf(STR1, "Track %3ld was already empty", CurTrack);
  4506.     WriteDebugInfo(STR1);
  4507.       }
  4508.  
  4509.  
  4510.       /* see if there was any note at all in the track ... */
  4511.       /* this is not OK....????? 26-3-'92 */
  4512.       if (WITH->NoteList.Size == 0) {
  4513.     SetTim(&WITH->Curtime, (int)MeasureCount,
  4514.         (int)PieceContr.TicksPerMeasure);
  4515.     InsertRest(&TrackArray[CurTrack - 1]);
  4516.       }
  4517.  
  4518.     }  /* For loop curtrack */
  4519.  
  4520.  
  4521.     /* Process the current measure in the Track's note arrays */
  4522.     fprintf(TexFile, "%%measure %1ld\n", MeasureCount + 1);
  4523.  
  4524.     /* see if there are any control events to start in this measure */
  4525.  
  4526.     CheckControls(MeasureCount);
  4527.  
  4528.     BeamIndex = 0;
  4529.     for (CurTrack = ntracks; CurTrack >= 1; CurTrack--) {
  4530.       WITH = &TrackArray[CurTrack - 1];
  4531.       if (!WITH->Skip && WITH->NoteList.Size > 0) {
  4532.     sprintf(STR1, "Start handling events in track :%3ld",CurTrack);
  4533.     WriteDebugInfo(STR1);
  4534.     FindNoteTypes(&TrackArray[TrackOrder[CurTrack - 1] - 1], MeasureCount);
  4535.     ChordFind(&TrackArray[TrackOrder[CurTrack - 1] - 1]);
  4536.     FindSlurrNote(&TrackArray[TrackOrder[CurTrack - 1] - 1], MeasureCount);
  4537.     BeamFind(&TrackArray[TrackOrder[CurTrack - 1] - 1]);
  4538.       }
  4539.     }
  4540.  
  4541.     FindMeasureParts((int)MeasureCount);
  4542.  
  4543.     PartCreateMeasure();
  4544.  
  4545.     CleanUpTracks();
  4546.  
  4547.   } while (!(AllTracksRead(ntracks)== true || SafetyCounter > 10000));
  4548.  
  4549.   fprintf(TexFile, "\\finmorceau\n");
  4550.   fprintf(TexFile, "\\bye\n");
  4551.   printf("\r\nTotal : %ld pages coded\r\n", NoOfPages);
  4552.   exit(0);
  4553. }
  4554.  
  4555.